package com.codeoss.framework.webide.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.codeoss.framework.context.YunContext;
import com.codeoss.framework.data.metadata.Column;
import com.codeoss.framework.data.metadata.Table;
import com.codeoss.framework.data.store.ITableStore;
import com.codeoss.framework.db.util.ValueNamePairUtil;
import com.codeoss.framework.util.StringUtils;
import com.codeoss.framework.util.ValueNamePair;
import com.codeoss.framework.view.datasource.DataSourceConfig;
import com.codeoss.framework.view.json.Button;
import com.codeoss.framework.view.json.Col;
import com.codeoss.framework.view.json.Div;
import com.codeoss.framework.view.json.Field;
import com.codeoss.framework.view.json.Icon;
import com.codeoss.framework.view.json.Label;
import com.codeoss.framework.view.json.MListView;
import com.codeoss.framework.view.json.MNavBar;
import com.codeoss.framework.view.json.Page;
import com.codeoss.framework.view.json.Row;
import com.codeoss.framework.view.json.TableColumn;
import com.codeoss.framework.view.json.Tree;
import com.codeoss.framework.view.json.TreeModel;
import com.codeoss.framework.view.json.TreePath;
import com.codeoss.framework.view.json.UReport2;
import com.codeoss.framework.view.util.ViewUtil;
import com.codeoss.framework.webide.dto.TableFieldDto;
import com.codeoss.framework.webide.dto.TableInfoDto;
import com.codeoss.framework.webide.request.PageWizardDialogRequest;
import com.codeoss.framework.webide.response.PageWizardDialogResponse;
import com.codeoss.framework.webide.service.IPageWizardDialogService;
import com.codeoss.module.ir.model.IrModel;
import com.codeoss.module.ir.model.IrPage;
import com.codeoss.module.ir.service.IIrDictService;
import com.codeoss.module.ir.service.IIrModelService;
import com.codeoss.module.ir.service.IIrPageService;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;

@Service
@Transactional
public class PageWizardDialogService implements IPageWizardDialogService {
	@Autowired
	private ObjectMapper objectMapper;
	@Autowired
	private IIrPageService irPageService;
	@Autowired
	private ITableStore tableStore;
	@Autowired
	private IIrModelService irModelService;
	@Autowired
	private ViewUtil viewUtil;
	@Autowired
    private IIrDictService irDictService;
	@Autowired
	private ValueNamePairUtil valueNamePairUtil;
	@Override
	@Transactional
	public PageWizardDialogResponse onFinish(PageWizardDialogRequest pageWizardDialogRequest) {
		// TODO Auto-generated method stub
		PageWizardDialogResponse pageWizardDialogResponse=new PageWizardDialogResponse();
		ObjectNode objectNode=null;
		try {
			objectNode=(ObjectNode)objectMapper.readTree(pageWizardDialogRequest.getJson());
		} catch (Exception e) {
			// TODO Auto-generated catch block
			throw new RuntimeException(e);
		}
		String device=objectNode.get("deviceSelectPage").get("device").asText();
		String pageType=objectNode.get("pageTypeSelectPage").get("pageType").asText();
		String pageCode=objectNode.get("pageBaseInfoPage").get("pageCode").asText();
		String pageName=objectNode.get("pageBaseInfoPage").get("name").asText();
		IrPage irPage=irPageService.getIrPageByPageCode(pageCode);
		if(irPage!=null) {
			throw new RuntimeException("页面代码已经存在");
		}
		if("pc".equals(device)) {
			if(pageType.equals("listview")) {
				createListView(pageWizardDialogRequest,objectNode);
			}else if(pageType.equals("formview")) {
				String tableName=objectNode.get("dataSourceSelectPage").get("tableName").asText();
				Table table=tableStore.get(tableName);
				if(!table.isTreeTable()) {
					createFormView(pageWizardDialogRequest,objectNode);
				}else {
					createTreeView(pageWizardDialogRequest, objectNode);
				}
			}else if(pageType.equals("searchview")) {
				String tableName=objectNode.get("dataSourceSelectPage").get("tableName").asText();
				Table table=tableStore.get(tableName);
				if(!table.isTreeTable()) {
					createSearchView(pageWizardDialogRequest,objectNode);
				}else {
					createTreeSearchView(pageWizardDialogRequest,objectNode);
				}
			}else if(pageType.equals("dashboardview")) {
				createDashboardview(pageWizardDialogRequest,objectNode);
			}else if(pageType.equals("ureportview")) {
				createUReportView(pageWizardDialogRequest,objectNode);
			}else if(pageType.equals("buttonparaview")) {
				createButtonParaView(pageWizardDialogRequest,objectNode);
			}else if(pageType.equals("actionview")) {
				createActionView(pageWizardDialogRequest,objectNode);
			}
		}else if("mobile".equals(device)) {
			if(pageType.equals("listview")) {
				createMobileListView(pageWizardDialogRequest,objectNode);
			}else if(pageType.equals("formview")) {
				createMobileFormView(pageWizardDialogRequest,objectNode);	
			}else if(pageType.equals("searchview")) {
				String tableName=objectNode.get("dataSourceSelectPage").get("tableName").asText();
				Table table=tableStore.get(tableName);
				if(!table.isTreeTable()) {
					createMobileSearchView(pageWizardDialogRequest,objectNode);
				}else {
					createMobileTreeSearchView(pageWizardDialogRequest,objectNode);
				}
			}else if(pageType.equals("dashboardview")) {
				createMobileDashboardview(pageWizardDialogRequest,objectNode);
			}else if(pageType.equals("ureportview")) {
				createMobileUReportView(pageWizardDialogRequest,objectNode);
			}else if(pageType.equals("buttonparaview")) {
				createMobileButtonParaView(pageWizardDialogRequest,objectNode);
			}else if(pageType.equals("actionview")) {
				createMobileActionView(pageWizardDialogRequest,objectNode);
			}else if(pageType.equals("detailview")) {
				createMobileDetailView(pageWizardDialogRequest,objectNode);
			}
		}
		pageWizardDialogResponse.setDevice(device);
		pageWizardDialogResponse.setPageCode(pageCode);
		pageWizardDialogResponse.setPageName(pageName);
		return pageWizardDialogResponse;
	}
	
	private void createMobileDetailView(PageWizardDialogRequest pageWizardDialogRequest,ObjectNode objectNode) {
		String moduleType=objectNode.get("moduleTypeSelectPage").get("moduleType").asText();
		String tableName=objectNode.get("dataSourceSelectPage").get("tableName").asText();
		String pageCode=objectNode.get("pageBaseInfoPage").get("pageCode").asText();
		String pageName=objectNode.get("pageBaseInfoPage").get("name").asText();
		String pageDescription=objectNode.get("pageBaseInfoPage").get("description").asText();
		ArrayNode fieldList=(ArrayNode)objectNode.get("tableFieldSelectPage").get("fieldList");
		
		Table table = tableStore.get(tableName);
		int id = 1;

		TreeModel root = new TreeModel();
		root.setId("component" + id);
		root.setName(pageName);

		Page formPage = new Page();
		formPage.setId("component" + id);
		id++;

		formPage.addProperty("pageCode", pageCode);
		formPage.addProperty("title",pageName);
		formPage.addProperty("pageBean", "mDetailPageBean");
		
		List<DataSourceConfig> dataSourceConfigList = new ArrayList<DataSourceConfig>();
		formPage.setDataSourceList(dataSourceConfigList);

		DataSourceConfig dataSourceConfig = new DataSourceConfig();
		dataSourceConfigList.add(dataSourceConfig);
		dataSourceConfig.setId(tableName);
		dataSourceConfig.setName(table.getName());
		dataSourceConfig.setTableName(tableName);

		TreeModel navBarTreeModel = new TreeModel();
		navBarTreeModel.setId("component" + id);
		navBarTreeModel.setName(table.getName());
		root.addChild(navBarTreeModel);

		MNavBar navBar = new MNavBar();
		navBar.setId("component" + id);
		navBar.setTitle(pageName);
		id++;
		formPage.addComponent(navBar);

		for (int i = 0; i < fieldList.size(); i++) {
			ObjectNode fieldObjectNode =(ObjectNode)fieldList.get(i);
			String name =fieldObjectNode.get("name").asText();
			String columnName =fieldObjectNode.get("columnName").asText();
			boolean displayInList =fieldObjectNode.get("displayInList").asBoolean();
			if (!displayInList) {
				continue;
			}

			TreeModel fieldTreeModel = new TreeModel();
			fieldTreeModel.setId("component" + id);
			fieldTreeModel.setName(name);
			root.addChild(fieldTreeModel);

			String viewType = fieldObjectNode.get("viewType").asText();
			Field field = new Field();
			formPage.addComponent(field);
			field.setType(viewType);
			field.setId("component" + id);
			id++;
			field.setLabelExpression(name);
			field.addProperty("dataSource", tableName);
			field.addProperty("dataField", columnName);
		}
		
		ObjectMapper objectMapper = new ObjectMapper();
		try {
			String componentJson = objectMapper.writeValueAsString(formPage);
			List<TreeModel> rootList = new ArrayList<TreeModel>();
			rootList.add(root);
			String treeJson = objectMapper.writeValueAsString(rootList);
			IrPage irPage = new IrPage();
			irPage.setComponentModelJson(componentJson);
			irPage.setComponentTreeModelJson(treeJson);
			irPage.setCurrentComponentId(Long.parseLong(id + ""));
			irPage.setPageCode(pageCode);
			irPage.setName(pageName);
			irPage.setDevice("mobile");
			irPage.setPageType("detailview");
			irPage.setDescription(pageDescription);
			irPage.setModuleType(moduleType);
			
			irPageService.insert(irPage);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			throw new RuntimeException(e);
		}
	}
	
	private void createMobileActionView(PageWizardDialogRequest pageWizardDialogRequest,ObjectNode objectNode) {
		String moduleType=objectNode.get("moduleTypeSelectPage").get("moduleType").asText();
		String tableName=objectNode.get("dataSourceSelectPage").get("tableName").asText();
		String pageCode=objectNode.get("pageBaseInfoPage").get("pageCode").asText();
		String pageName=objectNode.get("pageBaseInfoPage").get("name").asText();
		String pageDescription=objectNode.get("pageBaseInfoPage").get("description").asText();
		ArrayNode fieldList=(ArrayNode)objectNode.get("tableFieldSelectPage").get("fieldList");
		
		Table table =null;
		if(!StringUtils.isEmpty(tableName)) {
			table = tableStore.get(tableName);
		}
		
		int id = 1;

		TreeModel root = new TreeModel();
		root.setId("component" + id);
		root.setName(pageName);

		Page searchPage = new Page();
		searchPage.setId("component" + id);
		id++;

		searchPage.addProperty("pageCode", pageCode);
		searchPage.addProperty("title", pageName);
		searchPage.addProperty("pageBean", "mButtonParaPageBean");
		
		List<DataSourceConfig> dataSourceConfigList = new ArrayList<DataSourceConfig>();
		searchPage.setDataSourceList(dataSourceConfigList);
        
		if(!StringUtils.isEmpty(tableName)) {
			DataSourceConfig dataSourceConfig = new DataSourceConfig();
			dataSourceConfigList.add(dataSourceConfig);
			dataSourceConfig.setId(tableName);
			dataSourceConfig.setName(table.getName());
			dataSourceConfig.setTableName(tableName);
		}

		TreeModel navBarTreeModel = new TreeModel();
		navBarTreeModel.setId("component" + id);
		navBarTreeModel.setName(pageName);
		root.addChild(navBarTreeModel);

		MNavBar navBar = new MNavBar();
		navBar.setId("component" + id);
		navBar.setTitle(pageName);
		id++;
		searchPage.addComponent(navBar);

		for (int i = 0; i < fieldList.size(); i++) {
			ObjectNode fieldObjectNode =(ObjectNode)fieldList.get(i);
			String name =fieldObjectNode.get("name").asText();
			String columnName =fieldObjectNode.get("columnName").asText();
			boolean displayInList =fieldObjectNode.get("displayInList").asBoolean();
			if (!displayInList) {
				continue;
			}

			TreeModel fieldTreeModel = new TreeModel();
			fieldTreeModel.setId("component" + id);
			fieldTreeModel.setName(name);
			root.addChild(fieldTreeModel);

			String viewType = fieldObjectNode.get("viewType").asText();
			Field field = new Field();
			searchPage.addComponent(field);
			field.setType(viewType);
			field.setId("component" + id);
			id++;
			field.setLabelExpression(name);
			field.addProperty("dataSource", tableName);
			field.addProperty("dataField", columnName);
		}
				
		ObjectMapper objectMapper = new ObjectMapper();
		try {
			String componentJson = objectMapper.writeValueAsString(searchPage);
			List<TreeModel> rootList = new ArrayList<TreeModel>();
			rootList.add(root);
			String treeJson = objectMapper.writeValueAsString(rootList);
			IrPage irPage = new IrPage();
			irPage.setComponentModelJson(componentJson);
			irPage.setComponentTreeModelJson(treeJson);
			irPage.setCurrentComponentId(Long.parseLong(id + ""));
			irPage.setPageCode(pageCode);
			irPage.setName(pageName);
			irPage.setDevice("mobile");
			irPage.setPageType("actionview");
			irPage.setDescription(pageDescription);
			irPage.setModuleType(moduleType);
			
			irPageService.insert(irPage);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			throw new RuntimeException(e);
		}
	}
	
	private void createMobileButtonParaView(PageWizardDialogRequest pageWizardDialogRequest,ObjectNode objectNode) {
		String moduleType=objectNode.get("moduleTypeSelectPage").get("moduleType").asText();
		String tableName=objectNode.get("dataSourceSelectPage").get("tableName").asText();
		String pageCode=objectNode.get("pageBaseInfoPage").get("pageCode").asText();
		String pageName=objectNode.get("pageBaseInfoPage").get("name").asText();
		String pageDescription=objectNode.get("pageBaseInfoPage").get("description").asText();
		ArrayNode fieldList=(ArrayNode)objectNode.get("tableFieldSelectPage").get("fieldList");
		
		Table table = tableStore.get(tableName);
		int id = 1;

		TreeModel root = new TreeModel();
		root.setId("component" + id);
		root.setName(pageName);

		Page searchPage = new Page();
		searchPage.setId("component" + id);
		id++;

		searchPage.addProperty("pageCode", pageCode);
		searchPage.addProperty("title", pageName);
		searchPage.addProperty("pageBean", "mButtonParaPageBean");
		
		List<DataSourceConfig> dataSourceConfigList = new ArrayList<DataSourceConfig>();
		searchPage.setDataSourceList(dataSourceConfigList);

		DataSourceConfig dataSourceConfig = new DataSourceConfig();
		dataSourceConfigList.add(dataSourceConfig);
		dataSourceConfig.setId(tableName);
		dataSourceConfig.setName(table.getName());
		dataSourceConfig.setTableName(tableName);

		TreeModel navBarTreeModel = new TreeModel();
		navBarTreeModel.setId("component" + id);
		navBarTreeModel.setName(pageName);
		root.addChild(navBarTreeModel);

		MNavBar navBar = new MNavBar();
		navBar.setId("component" + id);
		navBar.setTitle(pageName);
		id++;
		searchPage.addComponent(navBar);

		for (int i = 0; i < fieldList.size(); i++) {
			ObjectNode fieldObjectNode =(ObjectNode)fieldList.get(i);
			String name =fieldObjectNode.get("name").asText();
			String columnName =fieldObjectNode.get("columnName").asText();
			boolean displayInList =fieldObjectNode.get("displayInList").asBoolean();
			if (!displayInList) {
				continue;
			}

			TreeModel fieldTreeModel = new TreeModel();
			fieldTreeModel.setId("component" + id);
			fieldTreeModel.setName(name);
			root.addChild(fieldTreeModel);

			String viewType = fieldObjectNode.get("viewType").asText();
			Field field = new Field();
			searchPage.addComponent(field);
			field.setType(viewType);
			field.setId("component" + id);
			id++;
			field.setLabelExpression(name);
			field.addProperty("dataSource", tableName);
			field.addProperty("dataField", columnName);
		}
		
		TreeModel buttonRowTreeModel = new TreeModel();
		buttonRowTreeModel.setId("component" + id);
		buttonRowTreeModel.setName("行");
		root.addChild(buttonRowTreeModel);

		Row buttonRow = new Row();
		buttonRow.setId("component" + id);
		searchPage.addComponent(buttonRow);
		id++;

		TreeModel buttonTreeModel = new TreeModel();
		buttonTreeModel.setId("component" + id);
		buttonTreeModel.setName("查询");
		root.addChild(buttonTreeModel);

		Button button = new Button();
		searchPage.addComponent(button);
		searchPage.setId("component" + id);
		id++;
		button.setLabelExpression("确定");
		button.setBlock(false);
		button.addProperty("block", false);
		button.addProperty("onClickExpression", "@mButtonParaPageBean.onOk()");
				
		ObjectMapper objectMapper = new ObjectMapper();
		try {
			String componentJson = objectMapper.writeValueAsString(searchPage);
			List<TreeModel> rootList = new ArrayList<TreeModel>();
			rootList.add(root);
			String treeJson = objectMapper.writeValueAsString(rootList);
			IrPage irPage = new IrPage();
			irPage.setComponentModelJson(componentJson);
			irPage.setComponentTreeModelJson(treeJson);
			irPage.setCurrentComponentId(Long.parseLong(id + ""));
			irPage.setPageCode(pageCode);
			irPage.setName(pageName);
			irPage.setDevice("mobile");
			irPage.setPageType("buttonparaview");
			irPage.setDescription(pageDescription);
			irPage.setModuleType(moduleType);
			
			irPageService.insert(irPage);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			throw new RuntimeException(e);
		}
	}
	
	private void createMobileUReportView(PageWizardDialogRequest pageWizardDialogRequest,ObjectNode objectNode) {
		String moduleType=objectNode.get("moduleTypeSelectPage").get("moduleType").asText();
		String tableName=objectNode.get("dataSourceSelectPage").get("tableName").asText();
		String pageCode=objectNode.get("pageBaseInfoPage").get("pageCode").asText();
		String pageName=objectNode.get("pageBaseInfoPage").get("name").asText();
		String pageDescription=objectNode.get("pageBaseInfoPage").get("description").asText();
		ArrayNode fieldList=(ArrayNode)objectNode.get("tableFieldSelectPage").get("fieldList");
		String reportCode=objectNode.get("uReportSelectPage").get("reportCode").asText();
		
		Table table = tableStore.get(tableName);
		int id = 1;

		TreeModel root = new TreeModel();
		root.setId("component" + id);
		root.setName(pageName);

		Page uReportPage = new Page();
		uReportPage.setId("component" + id);
		id++;

		uReportPage.addProperty("pageCode", pageCode);
		uReportPage.addProperty("title", pageName);
		uReportPage.addProperty("pageBean", "mUReport2PageBean");
		
		List<DataSourceConfig> dataSourceConfigList = new ArrayList<DataSourceConfig>();
		uReportPage.setDataSourceList(dataSourceConfigList);

		DataSourceConfig dataSourceConfig = new DataSourceConfig();
		dataSourceConfigList.add(dataSourceConfig);
		dataSourceConfig.setId(tableName);
		dataSourceConfig.setName(table.getName());
		dataSourceConfig.setTableName(tableName);

		TreeModel navBarTreeModel = new TreeModel();
		navBarTreeModel.setId("component" + id);
		navBarTreeModel.setName(pageName);
		root.addChild(navBarTreeModel);

		MNavBar navBar = new MNavBar();
		navBar.setId("component" + id);
		navBar.setTitle(pageName);
		id++;
		uReportPage.addComponent(navBar);

		for (int i = 0; i < fieldList.size(); i++) {
			ObjectNode fieldObjectNode =(ObjectNode)fieldList.get(i);
			String name =fieldObjectNode.get("name").asText();
			String columnName =fieldObjectNode.get("columnName").asText();
			boolean displayInList =fieldObjectNode.get("displayInList").asBoolean();
			if (!displayInList) {
				continue;
			}

			TreeModel fieldTreeModel = new TreeModel();
			fieldTreeModel.setId("component" + id);
			fieldTreeModel.setName(name);
			root.addChild(fieldTreeModel);

			String viewType = fieldObjectNode.get("viewType").asText();
			Field field = new Field();
			uReportPage.addComponent(field);
			field.setType(viewType);
			field.setId("component" + id);
			id++;
			field.setLabelExpression(name);
			field.addProperty("dataSource", tableName);
			field.addProperty("dataField", columnName);
		}
		
		TreeModel searchButtonTreeModel = new TreeModel();
		searchButtonTreeModel.setId("component" + id);
		searchButtonTreeModel.setName("查询");
		root.addChild(searchButtonTreeModel);

		Button searchButton = new Button();
		searchButton.setId("component" + id);
		searchButton.setLabelExpression("查询");
		searchButton.setBlock(true);
		searchButton.addProperty("block", true);
		searchButton.addProperty("onClickExpression","@mUReport2PageBean.dataSearch()");
		uReportPage.addComponent(searchButton);
		id++;

		TreeModel pdfButtonTreeModel = new TreeModel();
		pdfButtonTreeModel.setId("component" + id);
		pdfButtonTreeModel.setName("PDF");
		root.addChild(searchButtonTreeModel);

		Button pdfButton = new Button();
		pdfButton.setId("component" + id);
		pdfButton.setLabelExpression("PDF");
		pdfButton.setBlock(true);
		pdfButton.addProperty("block", true);
		pdfButton.addProperty("onClickExpression","@mUReport2PageBean.dataExport('pdf','"+pageName+"')");
		uReportPage.addComponent(pdfButton);
		id++;

		TreeModel reportTreeModel = new TreeModel();
		reportTreeModel.setId("component" + id);
		reportTreeModel.setName("报表");
		root.addChild(reportTreeModel);

		UReport2 uReport2 = new UReport2();
		uReport2.setId("component" + id);
		uReport2.setReportCode(reportCode);
		uReport2.addProperty("cssStyleExpression","width:100%;");
		id++;
		uReportPage.addComponent(uReport2);
		
		
		
		ObjectMapper objectMapper = new ObjectMapper();
		try {
			String componentJson = objectMapper.writeValueAsString(uReportPage);
			List<TreeModel> rootList = new ArrayList<TreeModel>();
			rootList.add(root);
			String treeJson = objectMapper.writeValueAsString(rootList);
			IrPage irPage = new IrPage();
			irPage.setComponentModelJson(componentJson);
			irPage.setComponentTreeModelJson(treeJson);
			irPage.setCurrentComponentId(Long.parseLong(id + ""));
			irPage.setPageCode(pageCode);
			irPage.setName(pageName);
			irPage.setDevice("mobile");
			irPage.setPageType("ureportview");
			irPage.setDescription(pageDescription);
			irPage.setModuleType(moduleType);
			
			irPageService.insert(irPage);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			throw new RuntimeException(e);
		}
	}
	
	private void createMobileDashboardview(PageWizardDialogRequest pageWizardDialogRequest,ObjectNode objectNode) {
		String moduleType=objectNode.get("moduleTypeSelectPage").get("moduleType").asText();
		String pageCode=objectNode.get("pageBaseInfoPage").get("pageCode").asText();
		String pageName=objectNode.get("pageBaseInfoPage").get("name").asText();
		String pageDescription=objectNode.get("pageBaseInfoPage").get("description").asText();
		
		int id = 1;

		TreeModel root = new TreeModel();
		root.setId("component" + id);
		root.setName(pageName);

		Page dashboardPage = new Page();
		dashboardPage.setId("component" + id);
		id++;

		dashboardPage.addProperty("pageCode", pageCode);
		dashboardPage.addProperty("title", pageName);
		dashboardPage.addProperty("pageBean", "mDashboardPageBean");
	
		List<DataSourceConfig> dataSourceConfigList = new ArrayList<DataSourceConfig>();
		dashboardPage.setDataSourceList(dataSourceConfigList);
		
		TreeModel navBarTreeModel = new TreeModel();
		navBarTreeModel.setId("component" + id);
		navBarTreeModel.setName(pageName);
		root.addChild(navBarTreeModel);

		MNavBar navBar = new MNavBar();
		navBar.setId("component" + id);
		navBar.setTitle(pageName);
		id++;
		dashboardPage.addComponent(navBar);
		
		ObjectMapper objectMapper = new ObjectMapper();
		try {
			String componentJson = objectMapper.writeValueAsString(dashboardPage);
			List<TreeModel> rootList = new ArrayList<TreeModel>();
			rootList.add(root);
			String treeJson = objectMapper.writeValueAsString(rootList);
			IrPage irPage = new IrPage();
			irPage.setComponentModelJson(componentJson);
			irPage.setComponentTreeModelJson(treeJson);
			irPage.setCurrentComponentId(Long.parseLong(id + ""));
			irPage.setPageCode(pageCode);
			irPage.setName(pageName);
			irPage.setDevice("mobile");
			irPage.setPageType("dashboardview");
			irPage.setDescription(pageDescription);
			irPage.setModuleType(moduleType);
			irPageService.insert(irPage);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			throw new RuntimeException(e);
		}
	}
	
	private void createMobileTreeSearchView(PageWizardDialogRequest pageWizardDialogRequest,ObjectNode objectNode) {
		String moduleType=objectNode.get("moduleTypeSelectPage").get("moduleType").asText();
		String tableName=objectNode.get("dataSourceSelectPage").get("tableName").asText();
		String pageCode=objectNode.get("pageBaseInfoPage").get("pageCode").asText();
		String pageName=objectNode.get("pageBaseInfoPage").get("name").asText();
		String pageDescription=objectNode.get("pageBaseInfoPage").get("description").asText();
		ArrayNode fieldList=(ArrayNode)objectNode.get("tableFieldSelectPage").get("fieldList");
		
		Table table = tableStore.get(tableName);
		int id = 1;

		TreeModel root = new TreeModel();
		root.setId("component" + id);
		root.setName(pageName);

		Page searchPage = new Page();
		searchPage.setId("component" + id);
		id++;

		searchPage.addProperty("pageCode", pageCode);
		searchPage.addProperty("title", pageName);
		searchPage.addProperty("pageBean", "mSearchTreeViewPageBean");
		
		List<DataSourceConfig> dataSourceConfigList = new ArrayList<DataSourceConfig>();
		searchPage.setDataSourceList(dataSourceConfigList);

		DataSourceConfig dataSourceConfig = new DataSourceConfig();
		dataSourceConfigList.add(dataSourceConfig);
		dataSourceConfig.setId(tableName);
		dataSourceConfig.setName(table.getName());
		dataSourceConfig.setTableName(tableName);

		TreeModel navBarTreeModel = new TreeModel();
		navBarTreeModel.setId("component" + id);
		navBarTreeModel.setName(pageName);
		root.addChild(navBarTreeModel);

		MNavBar navBar = new MNavBar();
		navBar.setId("component" + id);
		navBar.setTitle(table.getName());
		id++;
		searchPage.addComponent(navBar);

		TreeModel treePathTreeModel = new TreeModel();
		treePathTreeModel.setId("component" + id);
		treePathTreeModel.setName("树路径");
		root.addChild(treePathTreeModel);

		TreePath treePath = new TreePath();
		treePath.setId("component" + id);
		treePath.addProperty("onItemClickExpression", "@mSearchTreeViewPageBean.onItemClickHandler()");
		searchPage.addComponent(treePath);
		id++;

		TreeModel listViewTreeModel = new TreeModel();
		listViewTreeModel.setId("component" + id);
		listViewTreeModel.setName("列表视图");
		root.addChild(listViewTreeModel);

		MListView mListView = new MListView();
		mListView.setId("component" + id);
		mListView.setEditable(false);
		mListView.addProperty("dataSource", dataSourceConfig.getId());
		searchPage.addComponent(mListView);
		id++;

		TreeModel rowTreeModel = new TreeModel();
		rowTreeModel.setId("component" + id);
		rowTreeModel.setName("行");
		listViewTreeModel.addChild(rowTreeModel);

		Row row = new Row();
		row.setId("component" + id);
		mListView.addComponent(row);
		id++;

		TreeModel leftColTreeModel = new TreeModel();
		leftColTreeModel.setId("component" + id);
		leftColTreeModel.setName("列");
		rowTreeModel.addChild(leftColTreeModel);

		Col leftCol = new Col();
		leftCol.setId("component" + id);
		leftCol.setCol(16);
		row.addComponent(leftCol);
		id++;

		TreeModel divTreeModel = new TreeModel();
		divTreeModel.setId("component" + id);
		divTreeModel.setName("Div");
		leftColTreeModel.addChild(divTreeModel);

		Div div = new Div();
		div.setId("component" + id);
		div.addProperty("cssStyleExpression", "display:flex;flex-flow: column;");
		div.setCssStyle("display:flex;flex-flow: column;");
		leftCol.addComponent(div);
		id++;

		for (int i = 0; i < fieldList.size(); i++) {
			ObjectNode fieldObjectNode =(ObjectNode)fieldList.get(i);
			String name =fieldObjectNode.get("name").asText();
			String columnName =fieldObjectNode.get("columnName").asText();
			boolean displayInList =fieldObjectNode.get("displayInList").asBoolean();
			if (!displayInList) {
				continue;
			}

			TreeModel labelTreeModel = new TreeModel();
			labelTreeModel.setId("component" + id);
			labelTreeModel.setName(name);
			divTreeModel.addChild(labelTreeModel);

			Label label = new Label();
			label.setId("component" + id);
			id++;
			label.setLabelExpression(name);
			label.addProperty("dataSource",tableName);
			label.addProperty("dataField", columnName);
			div.addComponent(label);
		}

		TreeModel rightColTreeModel = new TreeModel();
		rightColTreeModel.setId("component" + id);
		rightColTreeModel.setName("列");
		rowTreeModel.addChild(rightColTreeModel);

		Col rightCol = new Col();
		rightCol.setId("component" + id);
		rightCol.setCol(8);
		row.addComponent(rightCol);
		id++;

		TreeModel selectButtonTreeModel = new TreeModel();
		selectButtonTreeModel.setId("component" + id);
		selectButtonTreeModel.setName("选择");
		rightColTreeModel.addChild(selectButtonTreeModel);

		Button selectButton = new Button();
		selectButton.setId("component" + id);
		selectButton.setLabelExpression("选择");
		selectButton.addProperty("onClickExpression","@mSearchTreeViewPageBean.dataSelected()");
		rightCol.addComponent(selectButton);
		id++;

		TreeModel childButtonTreeModel = new TreeModel();
		childButtonTreeModel.setId("component" + id);
		childButtonTreeModel.setName("下级");
		rightColTreeModel.addChild(childButtonTreeModel);

		Button childButton = new Button();
		childButton.setId("component" + id);
		childButton.setLabelExpression("下级");
		childButton.addProperty("onClickExpression", "@mSearchTreeViewPageBean.getChildren()");
		rightCol.addComponent(childButton);
		id++;
		

		ObjectMapper objectMapper = new ObjectMapper();
		try {
			String componentJson = objectMapper.writeValueAsString(searchPage);
			List<TreeModel> rootList = new ArrayList<TreeModel>();
			rootList.add(root);
			String treeJson = objectMapper.writeValueAsString(rootList);
			IrPage irPage = new IrPage();
			irPage.setComponentModelJson(componentJson);
			irPage.setComponentTreeModelJson(treeJson);
			irPage.setCurrentComponentId(Long.parseLong(id + ""));
			irPage.setPageCode(pageCode);
			irPage.setName(pageName);
			irPage.setDevice("mobile");
			irPage.setPageType("searchview");
			irPage.setDescription(pageDescription);
			irPage.setModuleType(moduleType);
			
			irPageService.insert(irPage);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			throw new RuntimeException(e);
		}
	}
	
	private void createMobileSearchView(PageWizardDialogRequest pageWizardDialogRequest,ObjectNode objectNode) {
		String moduleType=objectNode.get("moduleTypeSelectPage").get("moduleType").asText();
		String tableName=objectNode.get("dataSourceSelectPage").get("tableName").asText();
		String pageCode=objectNode.get("pageBaseInfoPage").get("pageCode").asText();
		String pageName=objectNode.get("pageBaseInfoPage").get("name").asText();
		String pageDescription=objectNode.get("pageBaseInfoPage").get("description").asText();
		ArrayNode fieldList=(ArrayNode)objectNode.get("tableFieldSelectPage").get("fieldList");
		
		Table table = tableStore.get(tableName);
		int id = 1;

		TreeModel root = new TreeModel();
		root.setId("component" + id);
		root.setName(pageName);

		Page searchPage = new Page();
		searchPage.setId("component" + id);
		id++;

		searchPage.addProperty("pageCode", pageCode);
		searchPage.addProperty("title", pageName);
		searchPage.addProperty("pageBean", "mSearchViewPageBean");
		
		List<DataSourceConfig> dataSourceConfigList = new ArrayList<DataSourceConfig>();
		searchPage.setDataSourceList(dataSourceConfigList);

		DataSourceConfig dataSourceConfig = new DataSourceConfig();
		dataSourceConfigList.add(dataSourceConfig);
		dataSourceConfig.setId(tableName);
		dataSourceConfig.setName(table.getName());
		dataSourceConfig.setTableName(tableName);

		TreeModel navBarTreeModel = new TreeModel();
		navBarTreeModel.setId("component" + id);
		navBarTreeModel.setName(table.getName());
		root.addChild(navBarTreeModel);

		MNavBar navBar = new MNavBar();
		navBar.setId("component" + id);
		navBar.setTitle(table.getName()+"查询");
		id++;
		searchPage.addComponent(navBar);

		for (int i = 0; i < fieldList.size(); i++) {
			ObjectNode fieldObjectNode =(ObjectNode)fieldList.get(i);
			String name =fieldObjectNode.get("name").asText();
			String columnName =fieldObjectNode.get("columnName").asText();
			boolean displayInSearch =fieldObjectNode.get("displayInSearch").asBoolean();
			if (!displayInSearch) {
				continue;
			}

			TreeModel fieldTreeModel = new TreeModel();
			fieldTreeModel.setId("component" + id);
			fieldTreeModel.setName(name);
			root.addChild(fieldTreeModel);

			String viewType = fieldObjectNode.get("viewType").asText();
			Field field = new Field();
			searchPage.addComponent(field);
			field.setType(viewType);
			field.setId("component" + id);
			id++;
			field.setLabelExpression(name);
			field.addProperty("dataSource", tableName);
			field.addProperty("dataField", columnName);
		}
		
		TreeModel buttonRowTreeModel = new TreeModel();
		buttonRowTreeModel.setId("component" + id);
		buttonRowTreeModel.setName("行");
		root.addChild(buttonRowTreeModel);

		Row buttonRow = new Row();
		buttonRow.setId("component" + id);
		searchPage.addComponent(buttonRow);
		id++;
		
		TreeModel buttonTreeModel = new TreeModel();
		buttonTreeModel.setId("component" + id);
		buttonTreeModel.setName("查询");
		root.addChild(buttonTreeModel);

		Button button = new Button();
		button.setId("component" + id);
		button.setLabelExpression("查询");
		button.setBlock(false);
		button.addProperty("block", false);
		button.addProperty("onClickExpression","@mSearchViewPageBean.dataSearch()");
		searchPage.addComponent(button);
		id++;

		TreeModel listViewTreeModel = new TreeModel();
		listViewTreeModel.setId("component" + id);
		listViewTreeModel.setName("列表");
		root.addChild(listViewTreeModel);
		
		MListView mListView = new MListView();
		mListView.setId("component" + id);
		mListView.setEditable(false);
		mListView.addProperty("dataSource", dataSourceConfig.getId());
		mListView.addProperty("pageable", true);
		mListView.addProperty("onPagination", "@mSearchViewPageBean.dataPage()");
		searchPage.addComponent(mListView);
		id++;

		
		TreeModel rowTreeModel = new TreeModel();
		rowTreeModel.setId("component" + id);
		rowTreeModel.setName("行");
		listViewTreeModel.addChild(rowTreeModel);

		Row row = new Row();
		row.setId("component" + id);
		mListView.addComponent(row);
		id++;

		TreeModel leftColTreeModel = new TreeModel();
		leftColTreeModel.setId("component" + id);
		leftColTreeModel.setName("列");
		rowTreeModel.addChild(leftColTreeModel);

		Col leftCol = new Col();
		leftCol.setId("component" + id);
		leftCol.setCol(16);
		row.addComponent(leftCol);
		id++;

		TreeModel divTreeModel = new TreeModel();
		divTreeModel.setId("component" + id);
		divTreeModel.setName("Div");
		leftColTreeModel.addChild(divTreeModel);

		Div div = new Div();
		div.setId("component" + id);
		div.addProperty("cssStyleExpression", "display:flex;flex-flow: column;");
		div.setCssStyle("display:flex;flex-flow: column;");
		leftCol.addComponent(div);
		id++;

		for (int i = 0; i < fieldList.size(); i++) {
			ObjectNode fieldObjectNode =(ObjectNode)fieldList.get(i);
			String name =fieldObjectNode.get("name").asText();
			String columnName =fieldObjectNode.get("columnName").asText();
			boolean displayInList =fieldObjectNode.get("displayInList").asBoolean();
			if (!displayInList) {
				continue;
			}

			TreeModel labelTreeModel = new TreeModel();
			labelTreeModel.setId("component" + id);
			labelTreeModel.setName(name);
			divTreeModel.addChild(labelTreeModel);

			Label label = new Label();
			label.setId("component" + id);
			id++;
			label.setLabelExpression(name);
			label.addProperty("dataSource", tableName);
			label.addProperty("dataField", columnName);
			div.addComponent(label);
		}

		TreeModel rightColTreeModel = new TreeModel();
		rightColTreeModel.setId("component" + id);
		rightColTreeModel.setName("列");
		rowTreeModel.addChild(rightColTreeModel);

		Col rightCol = new Col();
		rightCol.setId("component" + id);
		rightCol.setCol(8);
		row.addComponent(rightCol);
		id++;

		TreeModel selectedButtonTreeModel = new TreeModel();
		selectedButtonTreeModel.setId("component" + id);
		selectedButtonTreeModel.setName("选择");
		rightColTreeModel.addChild(selectedButtonTreeModel);

		Button detailButton = new Button();
		detailButton.setId("component" + id);
		detailButton.setLabelExpression("选择");
		detailButton.addProperty("onClickExpression","@mSearchViewPageBean.dataSelected()");
		rightCol.addComponent(detailButton);
		id++;
		
		
		ObjectMapper objectMapper = new ObjectMapper();
		try {
			String componentJson = objectMapper.writeValueAsString(searchPage);
			List<TreeModel> rootList = new ArrayList<TreeModel>();
			rootList.add(root);
			String treeJson = objectMapper.writeValueAsString(rootList);
			IrPage irPage = new IrPage();
			irPage.setComponentModelJson(componentJson);
			irPage.setComponentTreeModelJson(treeJson);
			irPage.setCurrentComponentId(Long.parseLong(id + ""));
			irPage.setPageCode(pageCode);
			irPage.setName(pageName);
			irPage.setDevice("mobile");
			irPage.setPageType("searchview");
			irPage.setDescription(pageDescription);
			irPage.setModuleType(moduleType);
			
			irPageService.insert(irPage);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			throw new RuntimeException(e);
		}
	}
	
	private void createMobileFormView(PageWizardDialogRequest pageWizardDialogRequest,ObjectNode objectNode) {
		String moduleType=objectNode.get("moduleTypeSelectPage").get("moduleType").asText();
		String tableName=objectNode.get("dataSourceSelectPage").get("tableName").asText();
		String pageCode=objectNode.get("pageBaseInfoPage").get("pageCode").asText();
		String pageName=objectNode.get("pageBaseInfoPage").get("name").asText();
		String pageDescription=objectNode.get("pageBaseInfoPage").get("description").asText();
		ArrayNode fieldList=(ArrayNode)objectNode.get("tableFieldSelectPage").get("fieldList");
		String subTableName=objectNode.get("dataSourceSelectPage").get("subTableName").asText();
		
		Table table = tableStore.get(tableName);
		int id = 1;

		TreeModel root = new TreeModel();
		root.setId("component" + id);
		root.setName(pageName);

		Page formPage = new Page();
		formPage.setId("component" + id);
		id++;

		formPage.addProperty("pageCode", pageCode);
		formPage.addProperty("title",pageName);
		if (!table.isTreeTable()) {
			formPage.addProperty("pageBean", "mFormViewPageBean");
		} else {
			formPage.addProperty("pageBean", "mTreeFormViewPageBean");
		}
		List<DataSourceConfig> dataSourceConfigList = new ArrayList<DataSourceConfig>();
		formPage.setDataSourceList(dataSourceConfigList);

		DataSourceConfig dataSourceConfig = new DataSourceConfig();
		dataSourceConfigList.add(dataSourceConfig);
		dataSourceConfig.setId(tableName);
		dataSourceConfig.setName(table.getName());
		dataSourceConfig.setTableName(tableName);

		TreeModel navBarTreeModel = new TreeModel();
		navBarTreeModel.setId("component" + id);
		navBarTreeModel.setName(table.getName());
		root.addChild(navBarTreeModel);

		MNavBar navBar = new MNavBar();
		navBar.setId("component" + id);
		navBar.setTitle(table.getName());
		navBar.setLeftArrowClickExpression("@mFormViewPageBean.backToList('"+"mobile_" + tableName + "_listview"+"')");
		id++;
		formPage.addComponent(navBar);

		if (table.isTreeTable()) {
			TreeModel treePathTreeModel = new TreeModel();
			treePathTreeModel.setId("component" + id);
			treePathTreeModel.setName("树路径");
			root.addChild(treePathTreeModel);

			TreePath treePath = new TreePath();
			treePath.setId("component" + id);
			formPage.addComponent(treePath);
			id++;
		}

		for (int i = 0; i < fieldList.size(); i++) {
			ObjectNode fieldObjectNode =(ObjectNode)fieldList.get(i);
			String name =fieldObjectNode.get("name").asText();
			String columnName =fieldObjectNode.get("columnName").asText();
			boolean displayInList =fieldObjectNode.get("displayInList").asBoolean();
			if (!displayInList) {
				continue;
			}

			TreeModel fieldTreeModel = new TreeModel();
			fieldTreeModel.setId("component" + id);
			fieldTreeModel.setName(name);
			root.addChild(fieldTreeModel);

			String viewType = fieldObjectNode.get("viewType").asText();
			Field field = new Field();
			formPage.addComponent(field);
			field.setType(viewType);
			field.setId("component" + id);
			id++;
			field.setLabelExpression(name);
			field.addProperty("dataSource", tableName);
			field.addProperty("dataField", columnName);
		}
		
		if(!StringUtils.isEmpty(subTableName)) {
			DataSourceConfig subDataSourceConfig = new DataSourceConfig();
			dataSourceConfigList.add(subDataSourceConfig);
			Table subTable=tableStore.get(subTableName);
			subDataSourceConfig.setId(subTableName);
			subDataSourceConfig.setName(subTable.getName());
			subDataSourceConfig.setTableName(subTableName);
			
			ArrayNode subFieldList=(ArrayNode)objectNode.get("tableFieldSelectPage").get("subFieldList");
			
			TreeModel listViewTreeModel = new TreeModel();
			listViewTreeModel.setId("component" + id);
			listViewTreeModel.setName("列表视图");
			root.addChild(listViewTreeModel);

			MListView mListView = new MListView();
			mListView.setId("component" + id);
			mListView.setEditable(true);
			mListView.addProperty("dataSource", subTableName);
			formPage.addComponent(mListView);
			id++;

			TreeModel rowTreeModel = new TreeModel();
			rowTreeModel.setId("component" + id);
			rowTreeModel.setName("行");
			listViewTreeModel.addChild(rowTreeModel);

			Row row = new Row();
			row.setId("component" + id);
			mListView.addComponent(row);
			id++;
		
			for (int i = 0; i < subFieldList.size(); i++) {
				ObjectNode fieldObjectNode =(ObjectNode)subFieldList.get(i);
				String name =fieldObjectNode.get("name").asText();
				String columnName =fieldObjectNode.get("columnName").asText();
				boolean displayInList =fieldObjectNode.get("displayInList").asBoolean();
				if (!displayInList) {
					continue;
				}

				TreeModel divTreeModel = new TreeModel();
				divTreeModel.setId("component" + id);
				divTreeModel.setName("Div");
				rowTreeModel.addChild(divTreeModel);

				Div div = new Div();
				div.setId("component" + id);
				div.addProperty("cssStyleExpression","width:100%;");
				row.addComponent(div);
				id++;
				
				TreeModel labelTreeModel = new TreeModel();
				labelTreeModel.setId("component" + id);
				labelTreeModel.setName(name);
				divTreeModel.addChild(labelTreeModel);

				Label label = new Label();
				label.setId("component" + id);
				id++;
				label.setLabelExpression(name);
				label.addProperty("dataSource", subTableName);
				label.addProperty("dataField", columnName);
				div.addComponent(label);
			}
		}
		
		TreeModel saveButtonTreeModel = new TreeModel();
		saveButtonTreeModel.setId("component" + id);
		saveButtonTreeModel.setName("保存");
		root.addChild(saveButtonTreeModel);

		Button saveButton = new Button();
		saveButton.setId("component" + id);
		saveButton.setLabelExpression("保存");
		saveButton.setBlock(true);
		saveButton.addProperty("block", true);
		if(table.isTreeTable()) {
			saveButton.addProperty("onClickExpression", "@mTreeFormViewPageBean.dataSave()");
		}else {
			saveButton.addProperty("onClickExpression", "@mFormViewPageBean.dataSave()");
		}
		formPage.addComponent(saveButton);
		id++;

		TreeModel newButtonTreeModel = new TreeModel();
		newButtonTreeModel.setId("component" + id);
		newButtonTreeModel.setName("新建");
		root.addChild(newButtonTreeModel);

		Button newButton = new Button();
		newButton.setId("component" + id);
		newButton.setLabelExpression("新建");
		newButton.setBlock(true);
		newButton.addProperty("block", true);
		if(table.isTreeTable()) {
			newButton.addProperty("onClickExpression", "@mTreeFormViewPageBean.dataNew()");
		}else {
			newButton.addProperty("onClickExpression", "@mFormViewPageBean.dataNew()");
		}
		formPage.addComponent(newButton);
		id++;
		
		TreeModel deleteButtonTreeModel = new TreeModel();
		deleteButtonTreeModel.setId("component" + id);
		deleteButtonTreeModel.setName("删除");
		root.addChild(deleteButtonTreeModel);

		Button deleteButton = new Button();
		deleteButton.setId("component" + id);
		deleteButton.setLabelExpression("删除");
		deleteButton.setBlock(true);
		deleteButton.addProperty("block", true);
		deleteButton.addProperty("confirmMessage", "确认删除吗?");
		if(table.isTreeTable()) {
			deleteButton.addProperty("onClickExpression", "@mTreeFormViewPageBean.dataDelete()");
		}else {
			deleteButton.addProperty("onClickExpression", "@mFormViewPageBean.dataDelete()");
		}
		formPage.addComponent(deleteButton);
		id++;
		

		
		ObjectMapper objectMapper = new ObjectMapper();
		try {
			String componentJson = objectMapper.writeValueAsString(formPage);
			List<TreeModel> rootList = new ArrayList<TreeModel>();
			rootList.add(root);
			String treeJson = objectMapper.writeValueAsString(rootList);
			IrPage irPage = new IrPage();
			irPage.setComponentModelJson(componentJson);
			irPage.setComponentTreeModelJson(treeJson);
			irPage.setCurrentComponentId(Long.parseLong(id + ""));
			irPage.setPageCode(pageCode);
			irPage.setName(pageName);
			irPage.setDevice("mobile");
			irPage.setPageType("formview");
			irPage.setDescription(pageDescription);
			irPage.setModuleType(moduleType);
			
			irPageService.insert(irPage);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			throw new RuntimeException(e);
		}
	}
	
	private void createMobileListView(PageWizardDialogRequest pageWizardDialogRequest,ObjectNode objectNode) {
		String moduleType=objectNode.get("moduleTypeSelectPage").get("moduleType").asText();
		String tableName=objectNode.get("dataSourceSelectPage").get("tableName").asText();
		String pageCode=objectNode.get("pageBaseInfoPage").get("pageCode").asText();
		String pageName=objectNode.get("pageBaseInfoPage").get("name").asText();
		String pageDescription=objectNode.get("pageBaseInfoPage").get("description").asText();
		ArrayNode fieldList=(ArrayNode)objectNode.get("tableFieldSelectPage").get("fieldList");
		
		Table table = tableStore.get(tableName);
		int id = 1;

		TreeModel root = new TreeModel();
		root.setId("component" + id);
		root.setName("手机端"+table.getName() + "列表视图");

		Page listPage = new Page();
		listPage.setId("component" + id);
		id++;

		listPage.addProperty("pageCode", pageCode);
		listPage.addProperty("title", pageName);
		if (!table.isTreeTable()) {
			listPage.addProperty("pageBean", "mListViewPageBean");
		} else {
			listPage.addProperty("pageBean", "mTreeListViewPageBean");
		}
		List<DataSourceConfig> dataSourceConfigList = new ArrayList<DataSourceConfig>();
		listPage.setDataSourceList(dataSourceConfigList);

		DataSourceConfig dataSourceConfig = new DataSourceConfig();
		dataSourceConfigList.add(dataSourceConfig);
		dataSourceConfig.setId(tableName);
		dataSourceConfig.setName(table.getName());
		dataSourceConfig.setTableName(tableName);

		TreeModel navBarTreeModel = new TreeModel();
		navBarTreeModel.setId("component" + id);
		navBarTreeModel.setName(table.getName());
		root.addChild(navBarTreeModel);

		MNavBar navBar = new MNavBar();
		navBar.setId("component" + id);
		navBar.setTitle(table.getName());
		id++;
		listPage.addComponent(navBar);

		if (table.isTreeTable()) {
			TreeModel treePathTreeModel = new TreeModel();
			treePathTreeModel.setId("component" + id);
			treePathTreeModel.setName("树路径");
			root.addChild(treePathTreeModel);

			TreePath treePath = new TreePath();
			treePath.setId("component" + id);
			treePath.addProperty("onItemClickExpression", "@mTreeListViewPageBean.onItemClickHandler()");
			listPage.addComponent(treePath);
			id++;
		}

		TreeModel buttonTreeModel = new TreeModel();
		buttonTreeModel.setId("component" + id);
		buttonTreeModel.setName("新建");
		root.addChild(buttonTreeModel);

		Button button = new Button();
		button.setId("component" + id);
		button.setLabelExpression("新建");
		button.setBlock(true);
		button.addProperty("block", true);
		if(table.isTreeTable()) {
			button.addProperty("onClickExpression",
					"@mTreeListViewPageBean.dataNew('mobile_" + table.getTableName() + "_formview')");
		}else {
			button.addProperty("onClickExpression",
					"@mListViewPageBean.dataNew('mobile_" + table.getTableName() + "_formview')");
		}
		
		listPage.addComponent(button);
		id++;

		TreeModel listViewTreeModel = new TreeModel();
		listViewTreeModel.setId("component" + id);
		listViewTreeModel.setName("列表视图");
		root.addChild(listViewTreeModel);

		MListView mListView = new MListView();
		mListView.setId("component" + id);
		mListView.setEditable(false);
		mListView.addProperty("dataSource", dataSourceConfig.getId());
		if (!table.isTreeTable()) {
			mListView.addProperty("pageable", true);
			mListView.addProperty("onPagination", "@mListViewPageBean.dataPage()");
		}
		listPage.addComponent(mListView);
		id++;

		TreeModel rowTreeModel = new TreeModel();
		rowTreeModel.setId("component" + id);
		rowTreeModel.setName("行");
		listViewTreeModel.addChild(rowTreeModel);

		Row row = new Row();
		row.setId("component" + id);
		mListView.addComponent(row);
		id++;

		TreeModel leftColTreeModel = new TreeModel();
		leftColTreeModel.setId("component" + id);
		leftColTreeModel.setName("列");
		rowTreeModel.addChild(leftColTreeModel);

		Col leftCol = new Col();
		leftCol.setId("component" + id);
		leftCol.setCol(16);
		row.addComponent(leftCol);
		id++;

		TreeModel divTreeModel = new TreeModel();
		divTreeModel.setId("component" + id);
		divTreeModel.setName("Div");
		leftColTreeModel.addChild(divTreeModel);

		Div div = new Div();
		div.setId("component" + id);
		div.addProperty("cssStyleExpression", "display:flex;flex-flow: column;");
		div.setCssStyle("display:flex;flex-flow: column;");
		leftCol.addComponent(div);
		id++;

	
		for (int i = 0; i < fieldList.size(); i++) {
			ObjectNode fieldObjectNode =(ObjectNode)fieldList.get(i);
			String name =fieldObjectNode.get("name").asText();
			String columnName =fieldObjectNode.get("columnName").asText();
			boolean displayInList =fieldObjectNode.get("displayInList").asBoolean();
			if (!displayInList) {
				continue;
			}

			TreeModel labelTreeModel = new TreeModel();
			labelTreeModel.setId("component" + id);
			labelTreeModel.setName(name);
			divTreeModel.addChild(labelTreeModel);

			Label label = new Label();
			label.setId("component" + id);
			id++;
			label.setLabelExpression(name);
			label.addProperty("dataSource", tableName);
			label.addProperty("dataField", columnName);
			div.addComponent(label);
		}

		TreeModel rightColTreeModel = new TreeModel();
		rightColTreeModel.setId("component" + id);
		rightColTreeModel.setName("列");
		rowTreeModel.addChild(rightColTreeModel);

		Col rightCol = new Col();
		rightCol.setId("component" + id);
		rightCol.setCol(8);
		row.addComponent(rightCol);
		id++;

		if (!table.isTreeTable()) {
			TreeModel detailButtonTreeModel = new TreeModel();
			detailButtonTreeModel.setId("component" + id);
			detailButtonTreeModel.setName("详情");
			rightColTreeModel.addChild(detailButtonTreeModel);

			Button detailButton = new Button();
			detailButton.setId("component" + id);
			detailButton.setLabelExpression("详情");
			detailButton.addProperty("onClickExpression",
					"@mListViewPageBean.dataEdit('mobile_" + table.getTableName() + "_formview')");
			rightCol.addComponent(detailButton);
			id++;
		} else {
			TreeModel detailButtonTreeModel = new TreeModel();
			detailButtonTreeModel.setId("component" + id);
			detailButtonTreeModel.setName("详情");
			rightColTreeModel.addChild(detailButtonTreeModel);

			Button detailButton = new Button();
			detailButton.setId("component" + id);
			detailButton.setLabelExpression("详情");
			detailButton.addProperty("onClickExpression",
					"@mTreeListViewPageBean.dataEdit('mobile_" + table.getTableName() + "_formview')");
			rightCol.addComponent(detailButton);
			id++;

			TreeModel childButtonTreeModel = new TreeModel();
			childButtonTreeModel.setId("component" + id);
			childButtonTreeModel.setName("下级");
			rightColTreeModel.addChild(childButtonTreeModel);

			Button childButton = new Button();
			childButton.setId("component" + id);
			childButton.setLabelExpression("下级");
			childButton.addProperty("onClickExpression", "@mTreeListViewPageBean.getChildren()");
			rightCol.addComponent(childButton);
			id++;
		}

		ObjectMapper objectMapper = new ObjectMapper();
		try {
			String componentJson = objectMapper.writeValueAsString(listPage);
			List<TreeModel> rootList = new ArrayList<TreeModel>();
			rootList.add(root);
			String treeJson = objectMapper.writeValueAsString(rootList);
			IrPage irPage = new IrPage();
			irPage.setComponentModelJson(componentJson);
			irPage.setComponentTreeModelJson(treeJson);
			irPage.setCurrentComponentId(Long.parseLong(id + ""));
			irPage.setPageCode(pageCode);
			irPage.setName(pageName);
			irPage.setDevice("mobile");
			irPage.setPageType("listview");
			irPage.setDescription(pageDescription);
			irPage.setModuleType(moduleType);
			
			irPageService.insert(irPage);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			throw new RuntimeException(e);
		}
	}
	
	private void createActionView(PageWizardDialogRequest pageWizardDialogRequest,ObjectNode objectNode) {
		String moduleType=objectNode.get("moduleTypeSelectPage").get("moduleType").asText();
		String tableName=objectNode.get("dataSourceSelectPage").get("tableName").asText();
		String pageCode=objectNode.get("pageBaseInfoPage").get("pageCode").asText();
		String pageName=objectNode.get("pageBaseInfoPage").get("name").asText();
		String pageDescription=objectNode.get("pageBaseInfoPage").get("description").asText();
		ArrayNode fieldList=(ArrayNode)objectNode.get("tableFieldSelectPage").get("fieldList");

		Table table =null;
		if(!StringUtils.isEmpty(tableName)) {
			table = tableStore.get(tableName);
		}
		

		int id = 1;

		TreeModel root = new TreeModel();
		root.setId("component" + id);
		root.setName(pageName);

		Page actionPage = new Page();
		actionPage.setId("component" + id);
		id++;

		actionPage.addProperty("pageCode", pageCode);
		actionPage.addProperty("title", pageName);
		actionPage.addProperty("pageBean", "actionPageBean");

		List<DataSourceConfig> dataSourceConfigList = new ArrayList<DataSourceConfig>();
		actionPage.setDataSourceList(dataSourceConfigList);
		
		if(table!=null) {
			DataSourceConfig dataSourceConfig = new DataSourceConfig();
			dataSourceConfigList.add(dataSourceConfig);
			dataSourceConfig.setId(tableName);
			dataSourceConfig.setName(table.getName());
			dataSourceConfig.setTableName(tableName);
		}
		
		TreeModel searchRowTreeModel = null;
		Row searchRow = null;
		int index = 0;
		for (int i = 0; i < fieldList.size(); i++) {
			ObjectNode fieldObjectNode =(ObjectNode)fieldList.get(i);
			String name =fieldObjectNode.get("name").asText();
			String columnName =fieldObjectNode.get("columnName").asText();
			boolean displayInSearch =fieldObjectNode.get("displayInList").asBoolean();
			if (!displayInSearch) {
				continue;
			}
			if (index % 2 == 0) {
				searchRowTreeModel = new TreeModel();
				searchRowTreeModel.setId("component" + id);
				searchRowTreeModel.setName("row");
				root.addChild(searchRowTreeModel);

				searchRow = new Row();
				searchRow.setId("component" + id);
				id++;
				actionPage.addComponent(searchRow);
			}

			TreeModel fieldTreeModel = new TreeModel();
			fieldTreeModel.setId("component" + id);
			fieldTreeModel.setName(name);
			searchRowTreeModel.addChild(fieldTreeModel);

			String viewType = fieldObjectNode.get("viewType").asText();
			Field field = new Field();
			searchRow.addComponent(field);
			field.setType(viewType);
			field.setId("component" + id);
			id++;
			field.setCol(2);
			field.setFieldcol(16);
			field.setLabelExpression(name);
			field.addProperty("dataSource", tableName);
			field.addProperty("dataField", columnName);

			index++;
		}


		ObjectMapper objectMapper = new ObjectMapper();
		try {
			String componentJson = objectMapper.writeValueAsString(actionPage);
			List<TreeModel> rootList = new ArrayList<TreeModel>();
			rootList.add(root);
			String treeJson = objectMapper.writeValueAsString(rootList);
			IrPage irPage = new IrPage();
			irPage.setComponentModelJson(componentJson);
			irPage.setComponentTreeModelJson(treeJson);
			irPage.setCurrentComponentId(Long.parseLong(id + ""));
			irPage.setPageCode(pageCode);
			irPage.setName(pageName);
			irPage.setDevice("pc");
			irPage.setPageType("actionview");
			irPage.setDescription(pageDescription);
			irPage.setModuleType(moduleType);
			irPageService.insert(irPage);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			throw new RuntimeException(e);
		}
	}
	
	private void createButtonParaView(PageWizardDialogRequest pageWizardDialogRequest,ObjectNode objectNode) {
		String moduleType=objectNode.get("moduleTypeSelectPage").get("moduleType").asText();
		String tableName=objectNode.get("dataSourceSelectPage").get("tableName").asText();
		String pageCode=objectNode.get("pageBaseInfoPage").get("pageCode").asText();
		String pageName=objectNode.get("pageBaseInfoPage").get("name").asText();
		String pageDescription=objectNode.get("pageBaseInfoPage").get("description").asText();
		ArrayNode fieldList=(ArrayNode)objectNode.get("tableFieldSelectPage").get("fieldList");

		Table table = tableStore.get(tableName);

		int id = 1;

		TreeModel root = new TreeModel();
		root.setId("component" + id);
		root.setName(pageName);

		Page buttonParaPage = new Page();
		buttonParaPage.setId("component" + id);
		id++;

		buttonParaPage.addProperty("pageCode", pageCode);
		buttonParaPage.addProperty("title", pageName);
		buttonParaPage.addProperty("pageBean", "buttonParaPageBean");

		List<DataSourceConfig> dataSourceConfigList = new ArrayList<DataSourceConfig>();
		buttonParaPage.setDataSourceList(dataSourceConfigList);

		DataSourceConfig dataSourceConfig = new DataSourceConfig();
		dataSourceConfigList.add(dataSourceConfig);
		dataSourceConfig.setId(tableName);
		dataSourceConfig.setName(table.getName());
		dataSourceConfig.setTableName(tableName);

		TreeModel searchRowTreeModel = null;
		Row searchRow = null;
		int index = 0;
		for (int i = 0; i < fieldList.size(); i++) {
			ObjectNode fieldObjectNode =(ObjectNode)fieldList.get(i);
			String name =fieldObjectNode.get("name").asText();
			String columnName =fieldObjectNode.get("columnName").asText();
			boolean displayInSearch =fieldObjectNode.get("displayInList").asBoolean();
			if (!displayInSearch) {
				continue;
			}
			if (index % 2 == 0) {
				searchRowTreeModel = new TreeModel();
				searchRowTreeModel.setId("component" + id);
				searchRowTreeModel.setName("row");
				root.addChild(searchRowTreeModel);

				searchRow = new Row();
				searchRow.setId("component" + id);
				id++;
				buttonParaPage.addComponent(searchRow);
			}

			TreeModel fieldTreeModel = new TreeModel();
			fieldTreeModel.setId("component" + id);
			fieldTreeModel.setName(name);
			searchRowTreeModel.addChild(fieldTreeModel);

			String viewType = fieldObjectNode.get("viewType").asText();
			Field field = new Field();
			searchRow.addComponent(field);
			field.setType(viewType);
			field.setId("component" + id);
			id++;
			field.setCol(2);
			field.setFieldcol(16);
			field.setLabelExpression(name);
			field.addProperty("dataSource", tableName);
			field.addProperty("dataField", columnName);

			index++;
		}
		TreeModel rowTreeModel = new TreeModel();
		rowTreeModel.setId("component" + id);
		rowTreeModel.setName("row");
		root.addChild(rowTreeModel);

		Row row = new Row();
		row.setId("component" + id);
		id++;
		buttonParaPage.addComponent(row);

		TreeModel buttonTreeModel = new TreeModel();
		buttonTreeModel.setId("component" + id);
		buttonTreeModel.setName("确定");
		rowTreeModel.addChild(buttonTreeModel);

		Button button = new Button();
		row.addComponent(button);
		button.setId("component" + id);
		id++;
		button.setLabelExpression("确定");
		button.addProperty("onClickExpression", "@buttonParaPageBean.onOk()");


		ObjectMapper objectMapper = new ObjectMapper();
		try {
			String componentJson = objectMapper.writeValueAsString(buttonParaPage);
			List<TreeModel> rootList = new ArrayList<TreeModel>();
			rootList.add(root);
			String treeJson = objectMapper.writeValueAsString(rootList);
			IrPage irPage = new IrPage();
			irPage.setComponentModelJson(componentJson);
			irPage.setComponentTreeModelJson(treeJson);
			irPage.setCurrentComponentId(Long.parseLong(id + ""));
			irPage.setPageCode(pageCode);
			irPage.setName(pageName);
			irPage.setDevice("pc");
			irPage.setPageType("ureportview");
			irPage.setDescription(pageDescription);
			
			irPage.setModuleType(moduleType);
			
			irPageService.insert(irPage);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			throw new RuntimeException(e);
		}
	}
	
	private void createUReportView(PageWizardDialogRequest pageWizardDialogRequest,ObjectNode objectNode) {
		String moduleType=objectNode.get("moduleTypeSelectPage").get("moduleType").asText();
		String tableName=objectNode.get("dataSourceSelectPage").get("tableName").asText();
		String pageCode=objectNode.get("pageBaseInfoPage").get("pageCode").asText();
		String pageName=objectNode.get("pageBaseInfoPage").get("name").asText();
		String pageDescription=objectNode.get("pageBaseInfoPage").get("description").asText();
		ArrayNode fieldList=(ArrayNode)objectNode.get("tableFieldSelectPage").get("fieldList");
		String reportCode=objectNode.get("uReportSelectPage").get("reportCode").asText();
		Table table = tableStore.get(tableName);

		int id = 1;

		TreeModel root = new TreeModel();
		root.setId("component" + id);
		root.setName(pageName);

		Page uReportPage = new Page();
		uReportPage.setId("component" + id);
		id++;

		uReportPage.addProperty("pageCode", pageCode);
		uReportPage.addProperty("title", pageName);
		uReportPage.addProperty("pageBean", "uReport2PageBean");

		List<DataSourceConfig> dataSourceConfigList = new ArrayList<DataSourceConfig>();
		uReportPage.setDataSourceList(dataSourceConfigList);

		DataSourceConfig dataSourceConfig = new DataSourceConfig();
		dataSourceConfigList.add(dataSourceConfig);
		dataSourceConfig.setId(tableName);
		dataSourceConfig.setName(table.getName());
		dataSourceConfig.setTableName(tableName);

		TreeModel searchRowTreeModel = null;
		Row searchRow = null;
		int index = 0;
		for (int i = 0; i < fieldList.size(); i++) {
			ObjectNode fieldObjectNode =(ObjectNode)fieldList.get(i);
			String name =fieldObjectNode.get("name").asText();
			String columnName =fieldObjectNode.get("columnName").asText();
			boolean displayInSearch =fieldObjectNode.get("displayInList").asBoolean();
			if (!displayInSearch) {
				continue;
			}
			if (index % 2 == 0) {
				searchRowTreeModel = new TreeModel();
				searchRowTreeModel.setId("component" + id);
				searchRowTreeModel.setName("row");
				root.addChild(searchRowTreeModel);

				searchRow = new Row();
				searchRow.setId("component" + id);
				id++;
				uReportPage.addComponent(searchRow);
			}

			TreeModel fieldTreeModel = new TreeModel();
			fieldTreeModel.setId("component" + id);
			fieldTreeModel.setName(name);
			searchRowTreeModel.addChild(fieldTreeModel);

			String viewType = fieldObjectNode.get("viewType").asText();
			Field field = new Field();
			searchRow.addComponent(field);
			field.setType(viewType);
			field.setId("component" + id);
			id++;
			field.setCol(2);
			field.setFieldcol(16);
			field.setLabelExpression(name);
			field.addProperty("dataSource", tableName);
			field.addProperty("dataField", columnName);

			index++;
		}
		TreeModel rowTreeModel = new TreeModel();
		rowTreeModel.setId("component" + id);
		rowTreeModel.setName("row");
		root.addChild(rowTreeModel);

		Row row = new Row();
		row.setId("component" + id);
		id++;
		uReportPage.addComponent(row);

		TreeModel searchButtonTreeModel = new TreeModel();
		searchButtonTreeModel.setId("component" + id);
		searchButtonTreeModel.setName("查询");
		rowTreeModel.addChild(searchButtonTreeModel);

		Button searchButton = new Button();
		row.addComponent(searchButton);
		searchButton.setId("component" + id);
		id++;
		searchButton.setLabelExpression("查询");
		searchButton.addProperty("onClickExpression", "@uReport2PageBean.dataSearch()");

		TreeModel pdfButtonTreeModel = new TreeModel();
		pdfButtonTreeModel.setId("component" + id);
		pdfButtonTreeModel.setName("PDF");
		rowTreeModel.addChild(pdfButtonTreeModel);

		Button pdfButton = new Button();
		row.addComponent(pdfButton);
		pdfButton.setId("component" + id);
		id++;
		pdfButton.setLabelExpression("PDF");
		pdfButton.addProperty("onClickExpression","@uReport2PageBean.dataExport('pdf','"+pageName+"')");

		
		TreeModel reportTreeModel = new TreeModel();
		reportTreeModel.setId("component" + id);
		reportTreeModel.setName("报表");
		root.addChild(reportTreeModel);

		UReport2 uReport2 = new UReport2();
		uReport2.setId("component" + id);
		uReport2.setReportCode(reportCode);
		uReport2.addProperty("cssStyleExpression","width:100%;");
		id++;
		uReportPage.addComponent(uReport2);

		ObjectMapper objectMapper = new ObjectMapper();
		try {
			String componentJson = objectMapper.writeValueAsString(uReportPage);
			List<TreeModel> rootList = new ArrayList<TreeModel>();
			rootList.add(root);
			String treeJson = objectMapper.writeValueAsString(rootList);
			IrPage irPage = new IrPage();
			irPage.setComponentModelJson(componentJson);
			irPage.setComponentTreeModelJson(treeJson);
			irPage.setCurrentComponentId(Long.parseLong(id + ""));
			irPage.setPageCode(pageCode);
			irPage.setName(pageName);
			irPage.setDevice("pc");
			irPage.setPageType("ureportview");
			irPage.setDescription(pageDescription);
			
			irPage.setModuleType(moduleType);
			
			irPageService.insert(irPage);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			throw new RuntimeException(e);
		}
	}
	
	private void createDashboardview(PageWizardDialogRequest pageWizardDialogRequest,ObjectNode objectNode) {
		String moduleType=objectNode.get("moduleTypeSelectPage").get("moduleType").asText();
		String pageCode=objectNode.get("pageBaseInfoPage").get("pageCode").asText();
		String pageName=objectNode.get("pageBaseInfoPage").get("name").asText();
		String pageDescription=objectNode.get("pageBaseInfoPage").get("description").asText();
		
		int id = 1;

		TreeModel root = new TreeModel();
		root.setId("component" + id);
		root.setName(pageName);

		Page dashboardPage = new Page();
		dashboardPage.setId("component" + id);
		id++;

		dashboardPage.addProperty("pageCode", pageCode);
		dashboardPage.addProperty("title", pageName);
		dashboardPage.addProperty("pageBean", "dashboardPageBean");
	
		List<DataSourceConfig> dataSourceConfigList = new ArrayList<DataSourceConfig>();
		dashboardPage.setDataSourceList(dataSourceConfigList);
		
		ObjectMapper objectMapper = new ObjectMapper();
		try {
			String componentJson = objectMapper.writeValueAsString(dashboardPage);
			List<TreeModel> rootList = new ArrayList<TreeModel>();
			rootList.add(root);
			String treeJson = objectMapper.writeValueAsString(rootList);
			IrPage irPage = new IrPage();
			irPage.setComponentModelJson(componentJson);
			irPage.setComponentTreeModelJson(treeJson);
			irPage.setCurrentComponentId(Long.parseLong(id + ""));
			irPage.setPageCode(pageCode);
			irPage.setName(pageName);
			irPage.setDevice("pc");
			irPage.setPageType("dashboardview");
			irPage.setDescription(pageDescription);
			irPage.setModuleType(moduleType);
			irPageService.insert(irPage);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			throw new RuntimeException(e);
		}
	}
	
	private void createTreeSearchView(PageWizardDialogRequest pageWizardDialogRequest,ObjectNode objectNode) {
		String moduleType=objectNode.get("moduleTypeSelectPage").get("moduleType").asText();
		String tableName=objectNode.get("dataSourceSelectPage").get("tableName").asText();
		String pageCode=objectNode.get("pageBaseInfoPage").get("pageCode").asText();
		String pageName=objectNode.get("pageBaseInfoPage").get("name").asText();
		String pageDescription=objectNode.get("pageBaseInfoPage").get("description").asText();
		
		Table table = tableStore.get(tableName);
		
		int id = 1;

		TreeModel root = new TreeModel();
		root.setId("component" + id);
		root.setName(pageName);

		Page searchPage = new Page();
		searchPage.setId("component" + id);
		id++;

		searchPage.addProperty("pageCode", pageCode);
		searchPage.addProperty("title", pageName);
		searchPage.addProperty("pageBean", "searchTreeViewPageBean");

		List<DataSourceConfig> dataSourceConfigList = new ArrayList<DataSourceConfig>();
		searchPage.setDataSourceList(dataSourceConfigList);

		DataSourceConfig dataSourceConfig = new DataSourceConfig();
		dataSourceConfigList.add(dataSourceConfig);
		dataSourceConfig.setId(tableName);
		dataSourceConfig.setName(table.getName());
		dataSourceConfig.setTableName(tableName);
		
		TreeModel treeModel = new TreeModel();
		treeModel.setId("component" + id);
		treeModel.setName("tree");
		root.addChild(treeModel);
		
		Tree tree = new Tree();
		tree.setId("component" + id);
		tree.addProperty("dataSource", tableName);
		tree.addProperty("onItemClickExpression","@searchTreeViewPageBean.onTreeItemClickHandler()");
		tree.addProperty("varName",tableName+"_tree_id");
		id++;
		searchPage.addComponent(tree);
		
		ObjectMapper objectMapper = new ObjectMapper();
		try {
			String componentJson = objectMapper.writeValueAsString(searchPage);
			List<TreeModel> rootList = new ArrayList<TreeModel>();
			rootList.add(root);
			String treeJson = objectMapper.writeValueAsString(rootList);
			IrPage irPage = new IrPage();
			irPage.setComponentModelJson(componentJson);
			irPage.setComponentTreeModelJson(treeJson);
			irPage.setCurrentComponentId(Long.parseLong(id + ""));
			irPage.setPageCode(pageCode);
			irPage.setName(pageName);
			irPage.setDevice("pc");
			irPage.setPageType("searchview");
			irPage.setDescription(pageDescription);
			irPage.setModuleType(moduleType);
			
			irPageService.insert(irPage);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			throw new RuntimeException(e);
		}
	}
	
	private void createSearchView(PageWizardDialogRequest pageWizardDialogRequest,ObjectNode objectNode) {
		String moduleType=objectNode.get("moduleTypeSelectPage").get("moduleType").asText();
		String tableName=objectNode.get("dataSourceSelectPage").get("tableName").asText();
		String pageCode=objectNode.get("pageBaseInfoPage").get("pageCode").asText();
		String pageName=objectNode.get("pageBaseInfoPage").get("name").asText();
		String pageDescription=objectNode.get("pageBaseInfoPage").get("description").asText();
		ArrayNode fieldList=(ArrayNode)objectNode.get("tableFieldSelectPage").get("fieldList");
		
		Table table = tableStore.get(tableName);

		int id = 1;

		TreeModel root = new TreeModel();
		root.setId("component" + id);
		root.setName(pageName);

		Page searchPage = new Page();
		searchPage.setId("component" + id);
		id++;

		searchPage.addProperty("pageCode", pageCode);
		searchPage.addProperty("title", pageName);
		searchPage.addProperty("pageBean", "searchViewPageBean");

		List<DataSourceConfig> dataSourceConfigList = new ArrayList<DataSourceConfig>();
		searchPage.setDataSourceList(dataSourceConfigList);

		DataSourceConfig dataSourceConfig = new DataSourceConfig();
		dataSourceConfigList.add(dataSourceConfig);
		dataSourceConfig.setId(tableName);
		dataSourceConfig.setName(table.getName());
		dataSourceConfig.setTableName(tableName);

		TreeModel searchRowTreeModel = null;
		Row searchRow = null;
		int index = 0;
		for (int i = 0; i < fieldList.size(); i++) {
			ObjectNode fieldObjectNode =(ObjectNode)fieldList.get(i);
			String name =fieldObjectNode.get("name").asText();
			String columnName =fieldObjectNode.get("columnName").asText();
			boolean displayInSearch =fieldObjectNode.get("displayInSearch").asBoolean();
			if (!displayInSearch) {
				continue;
			}
			if (index % 2 == 0) {
				searchRowTreeModel = new TreeModel();
				searchRowTreeModel.setId("component" + id);
				searchRowTreeModel.setName("row");
				root.addChild(searchRowTreeModel);

				searchRow = new Row();
				searchRow.setId("component" + id);
				id++;
				searchPage.addComponent(searchRow);
			}

			TreeModel fieldTreeModel = new TreeModel();
			fieldTreeModel.setId("component" + id);
			fieldTreeModel.setName(name);
			searchRowTreeModel.addChild(fieldTreeModel);

			String viewType = fieldObjectNode.get("viewType").asText();
			Field field = new Field();
			searchRow.addComponent(field);
			field.setType(viewType);
			field.setId("component" + id);
			id++;
			field.setCol(2);
			field.setFieldcol(16);
			field.setLabelExpression(name);
			field.addProperty("dataSource", tableName);
			field.addProperty("dataField", columnName);

			index++;
		}
		TreeModel rowTreeModel = new TreeModel();
		rowTreeModel.setId("component" + id);
		rowTreeModel.setName("row");
		root.addChild(rowTreeModel);

		Row row = new Row();
		row.setId("component" + id);
		id++;
		searchPage.addComponent(row);

		TreeModel searchButtonTreeModel = new TreeModel();
		searchButtonTreeModel.setId("component" + id);
		searchButtonTreeModel.setName("查询");
		rowTreeModel.addChild(searchButtonTreeModel);

		Button searchButton = new Button();
		row.addComponent(searchButton);
		searchButton.setId("component" + id);
		id++;
		searchButton.setLabelExpression("查询");
		searchButton.addProperty("onClickExpression", "@searchViewPageBean.dataSearch()");

		TreeModel clearValueButtonTreeModel = new TreeModel();
		clearValueButtonTreeModel.setId("component" + id);
		clearValueButtonTreeModel.setName("清除值");
		rowTreeModel.addChild(clearValueButtonTreeModel);

		Button clearValueButton = new Button();
		row.addComponent(clearValueButton);
		clearValueButton.setId("component" + id);
		id++;
		clearValueButton.setLabelExpression("清除值");
		clearValueButton.addProperty("onClickExpression","@searchViewPageBean.clearValue()");

		TreeModel row2TreeModel = new TreeModel();
		row2TreeModel.setId("component" + id);
		row2TreeModel.setName("row");
		root.addChild(row2TreeModel);

		Row row2 = new Row();
		row2.setId("component" + id);
		id++;
		searchPage.addComponent(row2);

		TreeModel tableTreeModel = new TreeModel();
		tableTreeModel.setId("component" + id);
		tableTreeModel.setName("table");
		row2TreeModel.addChild(tableTreeModel);

		com.codeoss.framework.view.json.Table tableJson = new com.codeoss.framework.view.json.Table();
		tableJson.setId("component" + id);
		tableJson.addProperty("dataSource", table.getTableName());
		tableJson.addProperty("editable",false);
		tableJson.addProperty("pageable", true);
		tableJson.addProperty("onPagination", "@searchViewPageBean.dataPage()");
		tableJson.addProperty("multiSelect", false);
		id++;
		row2.addComponent(tableJson);

		for (int i = 0; i < fieldList.size(); i++) {
			ObjectNode fieldObjectNode =(ObjectNode)fieldList.get(i);
			String name =fieldObjectNode.get("name").asText();
			String columnName =fieldObjectNode.get("columnName").asText();
			boolean displayInList =fieldObjectNode.get("displayInList").asBoolean();
			if (!displayInList) {
				continue;
			}

			TreeModel tableColumnTreeModel = new TreeModel();
			tableColumnTreeModel.setId("component" + id);
			tableColumnTreeModel.setName(name);
			tableTreeModel.addChild(tableColumnTreeModel);

			TableColumn tableColumn = new TableColumn();
			tableColumn.setTitle(name);
			tableColumn.setId("component" + id);
			tableJson.addComponent(tableColumn);
			id++;

			TreeModel labelTreeModel = new TreeModel();
			labelTreeModel.setId("component" + id);
			labelTreeModel.setName(name);
			tableColumnTreeModel.addChild(labelTreeModel);

			Column column=table.getColumnByColumnName(columnName);
			if(column.getDataType().equals("boolean")) {
				Field field = new Field();
				field.setType("switch");
				field.setId("component" + id);
				id++;
				field.setLabelExpression(name);
				field.addProperty("dataSource", tableName);
				field.addProperty("dataField", columnName);
				field.setCol(4);
				field.setNoLabel(true);
				tableColumn.addComponent(field);
			}else if(column.getLookupInfo()!=null && column.getLookupInfo().getDictDef()!=null) {
				Field field = new Field();
				field.setType("tag");
				field.setId("component" + id);
				id++;
				field.setLabelExpression(name);
				field.addProperty("dataSource", tableName);
				field.addProperty("dataField", columnName);
				field.setCol(4);
				field.setNoLabel(true);
				tableColumn.addComponent(field);
			}else {
				Label label = new Label();
				label.setId("component" + id);
				id++;
				label.setLabelExpression(name);
				label.addProperty("dataSource", tableName);
				label.addProperty("dataField", columnName);
				tableColumn.addComponent(label);
			}
		}

		TreeModel actionColumnTreeModel = new TreeModel();
		actionColumnTreeModel.setId("component" + id);
		actionColumnTreeModel.setName("操作");
		tableTreeModel.addChild(actionColumnTreeModel);

		TableColumn actionTableColumn = new TableColumn();
		actionTableColumn.setTitle("操作");
		actionTableColumn.setId("component" + id);
		tableJson.addComponent(actionTableColumn);
		id++;

		TreeModel actionRowTreeModel = new TreeModel();
		actionRowTreeModel.setId("component" + id);
		actionRowTreeModel.setName("row");
		actionColumnTreeModel.addChild(actionRowTreeModel);

		Row actionRow = new Row();
		actionRow.setId("component" + id);
		id++;
		actionTableColumn.addComponent(actionRow);

		TreeModel selectedActionTreeModel = new TreeModel();
		selectedActionTreeModel.setId("component" + id);
		selectedActionTreeModel.setName("icon");
		actionRowTreeModel.addChild(selectedActionTreeModel);

		Icon selectedActionIcon = new Icon();
		selectedActionIcon.setId("component" + id);
		selectedActionIcon.setIconClass("el-icon-share");
		selectedActionIcon.addProperty("onClickExpression", "@searchViewPageBean.dataSelected()");
		id++;
		actionRow.addComponent(selectedActionIcon);

		ObjectMapper objectMapper = new ObjectMapper();
		try {
			String componentJson = objectMapper.writeValueAsString(searchPage);
			List<TreeModel> rootList = new ArrayList<TreeModel>();
			rootList.add(root);
			String treeJson = objectMapper.writeValueAsString(rootList);
			IrPage irPage = new IrPage();
			irPage.setComponentModelJson(componentJson);
			irPage.setComponentTreeModelJson(treeJson);
			irPage.setCurrentComponentId(Long.parseLong(id + ""));
			irPage.setPageCode(pageCode);
			irPage.setName(pageName);
			irPage.setDevice("pc");
			irPage.setPageType("searchview");
			irPage.setDescription(pageDescription);
			
			irPage.setModuleType(moduleType);
			
			irPageService.insert(irPage);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			throw new RuntimeException(e);
		}
	}
	
	
	private void createTreeView(PageWizardDialogRequest pageWizardDialogRequest,ObjectNode objectNode) {
		String moduleType=objectNode.get("moduleTypeSelectPage").get("moduleType").asText();
		String tableName=objectNode.get("dataSourceSelectPage").get("tableName").asText();
		String pageCode=objectNode.get("pageBaseInfoPage").get("pageCode").asText();
		String pageName=objectNode.get("pageBaseInfoPage").get("name").asText();
		String pageDescription=objectNode.get("pageBaseInfoPage").get("description").asText();
		ArrayNode fieldList=(ArrayNode)objectNode.get("tableFieldSelectPage").get("fieldList");
		
		Table table = tableStore.get(tableName);

		int id = 1;

		TreeModel root = new TreeModel();
		root.setId("component" + id);
		root.setName(pageName);

		Page treePage = new Page();
		treePage.setId("component" + id);
		id++;

		treePage.addProperty("pageCode", pageCode);
		treePage.addProperty("title",pageName);
		treePage.addProperty("pageBean", "treeViewPageBean");

		List<DataSourceConfig> dataSourceConfigList = new ArrayList<DataSourceConfig>();
		treePage.setDataSourceList(dataSourceConfigList);

		DataSourceConfig dataSourceConfig = new DataSourceConfig();
		dataSourceConfigList.add(dataSourceConfig);
		dataSourceConfig.setId(tableName);
		dataSourceConfig.setName(table.getName());
		dataSourceConfig.setTableName(tableName);

		TreeModel rowTreeModel = new TreeModel();
		rowTreeModel.setId("component" + id);
		rowTreeModel.setName("row");
		root.addChild(rowTreeModel);

		Row row = new Row();
		row.setId("component" + id);
		row.addProperty("cssStyleExpression", "display: flex;justify-content: center;border-bottom:1px solid #ddd;padding-bottom:5px;");
		id++;
		treePage.addComponent(row);

		TreeModel saveTreeModel = new TreeModel();
		saveTreeModel.setId("component" + id);
		saveTreeModel.setName("保存");
		rowTreeModel.addChild(saveTreeModel);

		Button saveButton = new Button();
		saveButton.setId("component" + id);
		saveButton.setLabelExpression("保存");
		saveButton.addProperty("onClickExpression", "@treeViewPageBean.dataSave()");
		id++;
		row.addComponent(saveButton);

		TreeModel newTreeModel = new TreeModel();
		newTreeModel.setId("component" + id);
		newTreeModel.setName("新建");
		rowTreeModel.addChild(newTreeModel);

		Button newButton = new Button();
		newButton.setId("component" + id);
		newButton.setLabelExpression("新建");
		newButton.addProperty("onClickExpression", "@treeViewPageBean.dataNew()");
		id++;
		row.addComponent(newButton);

		TreeModel deleteTreeModel = new TreeModel();
		deleteTreeModel.setId("component" + id);
		deleteTreeModel.setName("删除");
		rowTreeModel.addChild(deleteTreeModel);

		Button deleteButton = new Button();
		deleteButton.setId("component" + id);
		deleteButton.setLabelExpression("删除");
		deleteButton.addProperty("onClickExpression", "@treeViewPageBean.dataDelete()");
		id++;
		row.addComponent(deleteButton);

		TreeModel contentRowTreeModel = new TreeModel();
		contentRowTreeModel.setId("component" + id);
		contentRowTreeModel.setName("row");
		root.addChild(contentRowTreeModel);

		Row contentRow = new Row();
		contentRow.setId("component" + id);
		id++;
		treePage.addComponent(contentRow);

		TreeModel leftColTreeModel = new TreeModel();
		leftColTreeModel.setId("component" + id);
		leftColTreeModel.setName("row");
		contentRowTreeModel.addChild(leftColTreeModel);

		Col leftCol = new Col();
		leftCol.setCol(6);
		leftCol.setId("component" + id);
		id++;
		contentRow.addComponent(leftCol);

		TreeModel treeModel = new TreeModel();
		treeModel.setId("component" + id);
		treeModel.setName("tree");
		leftColTreeModel.addChild(treeModel);
		
		Tree tree = new Tree();
		tree.setId("component" + id);
		tree.addProperty("dataSource", tableName);
		tree.addProperty("onItemClickExpression","@treeViewPageBean.onTreeItemClickHandler()");
		tree.addProperty("varName","_"+tableName+"_parent_id");
		id++;
		leftCol.addComponent(tree);
		
		TreeModel rightColTreeModel = new TreeModel();
		rightColTreeModel.setId("component" + id);
		rightColTreeModel.setName("row");
		contentRowTreeModel.addChild(rightColTreeModel);

		Col rightCol = new Col();
		rightCol.setCol(18);
		rightCol.setId("component" + id);
		id++;
		contentRow.addComponent(rightCol);

		

		TreeModel formRowTreeModel = null;
		Row formRow = null;
		int index = 0;
		for (int i = 0; i < fieldList.size(); i++) {
			ObjectNode fieldObjectNode =(ObjectNode)fieldList.get(i);
			String name =fieldObjectNode.get("name").asText();
			String columnName =fieldObjectNode.get("columnName").asText();
			boolean displayInForm =fieldObjectNode.get("displayInList").asBoolean();
			if (!displayInForm) {
				continue;
			}
			if (index % 2 == 0) {
				formRowTreeModel = new TreeModel();
				formRowTreeModel.setId("component" + id);
				formRowTreeModel.setName("row");
				rightColTreeModel.addChild(formRowTreeModel);

				formRow = new Row();
				formRow.setId("component" + id);
				id++;
				rightCol.addComponent(formRow);
			}

			TreeModel fieldTreeModel = new TreeModel();
			fieldTreeModel.setId("component" + id);
			fieldTreeModel.setName(name);
			formRowTreeModel.addChild(fieldTreeModel);

			String viewType =fieldObjectNode.get("viewType").asText();
			Field field = new Field();
			formRow.addComponent(field);
			field.setType(viewType);
			field.setId("component" + id);
			id++;
			field.setCol(2);
			field.setFieldcol(16);
			field.setLabelExpression(name);
			field.addProperty("dataSource", tableName);
			field.addProperty("dataField", columnName);

			index++;
		}

		ObjectMapper objectMapper = new ObjectMapper();
		try {
			String componentJson = objectMapper.writeValueAsString(treePage);
			List<TreeModel> rootList = new ArrayList<TreeModel>();
			rootList.add(root);
			String treeJson = objectMapper.writeValueAsString(rootList);
			IrPage irPage = new IrPage();
			irPage.setComponentModelJson(componentJson);
			irPage.setComponentTreeModelJson(treeJson);
			irPage.setCurrentComponentId(Long.parseLong(id + ""));
			irPage.setPageCode(pageCode);
			irPage.setName(pageName);
			irPage.setDevice("pc");
			irPage.setPageType("formview");
			irPage.setDescription(pageDescription);
			irPage.setModuleType(moduleType);
			
			irPageService.insert(irPage);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			throw new RuntimeException(e);
		}

	}
	
	private void createFormView(PageWizardDialogRequest pageWizardDialogRequest,ObjectNode objectNode) {
		String moduleType=objectNode.get("moduleTypeSelectPage").get("moduleType").asText();
		String tableName=objectNode.get("dataSourceSelectPage").get("tableName").asText();
		String pageCode=objectNode.get("pageBaseInfoPage").get("pageCode").asText();
		String pageName=objectNode.get("pageBaseInfoPage").get("name").asText();
		String pageDescription=objectNode.get("pageBaseInfoPage").get("description").asText();
		ArrayNode fieldList=(ArrayNode)objectNode.get("tableFieldSelectPage").get("fieldList");
		String subTableName=objectNode.get("dataSourceSelectPage").get("subTableName").asText();
		
		Table table = tableStore.get(tableName);
		
		int id = 1;

		TreeModel root = new TreeModel();
		root.setId("component" + id);
		root.setName(pageName);

		Page formPage = new Page();
		formPage.setId("component" + id);
		id++;

		formPage.addProperty("pageCode", pageCode);
		formPage.addProperty("title", pageName);
		formPage.addProperty("pageBean", "formViewPageBean");

		List<DataSourceConfig> dataSourceConfigList = new ArrayList<DataSourceConfig>();
		formPage.setDataSourceList(dataSourceConfigList);

		DataSourceConfig dataSourceConfig = new DataSourceConfig();
		dataSourceConfigList.add(dataSourceConfig);
		dataSourceConfig.setId(tableName);
		dataSourceConfig.setName(table.getName());
		dataSourceConfig.setTableName(tableName);

		TreeModel rowTreeModel = new TreeModel();
		rowTreeModel.setId("component" + id);
		rowTreeModel.setName("row");
		root.addChild(rowTreeModel);

		Row row = new Row();
		row.setId("component" + id);
		row.addProperty("cssStyleExpression", "display: flex;justify-content: center;border-bottom:1px solid #ddd;padding-bottom:5px;");
		id++;
		formPage.addComponent(row);

		TreeModel saveTreeModel = new TreeModel();
		saveTreeModel.setId("component" + id);
		saveTreeModel.setName("保存");
		rowTreeModel.addChild(saveTreeModel);

		Button saveButton = new Button();
		saveButton.setId("component" + id);
		saveButton.setLabelExpression("保存");
		saveButton.addProperty("onClickExpression", "@formViewPageBean.dataSave()");
		id++;
		row.addComponent(saveButton);

		TreeModel newTreeModel = new TreeModel();
		newTreeModel.setId("component" + id);
		newTreeModel.setName("新建");
		rowTreeModel.addChild(newTreeModel);

		Button newButton = new Button();
		newButton.setId("component" + id);
		newButton.setLabelExpression("新建");
		newButton.addProperty("onClickExpression", "@formViewPageBean.dataNew()");
		id++;
		row.addComponent(newButton);

		TreeModel deleteTreeModel = new TreeModel();
		deleteTreeModel.setId("component" + id);
		deleteTreeModel.setName("删除");
		rowTreeModel.addChild(deleteTreeModel);

		Button deleteButton = new Button();
		deleteButton.setId("component" + id);
		deleteButton.setLabelExpression("删除");
		deleteButton.addProperty("onClickExpression", "@formViewPageBean.dataDelete()");
		deleteButton.addProperty("confirmMessage","确认要删除吗?");
		id++;
		row.addComponent(deleteButton);

		TreeModel backTreeModel = new TreeModel();
		backTreeModel.setId("component" + id);
		backTreeModel.setName("返回");
		rowTreeModel.addChild(backTreeModel);

		Button backButton = new Button();
		backButton.setId("component" + id);
		backButton.setLabelExpression("返回");
		backButton.addProperty("onClickExpression", "@formViewPageBean.backToList('"+table.getTableName()+"_listview')");
		id++;
		row.addComponent(backButton);
		
		TreeModel formRowTreeModel = null;
		Row formRow = null;
		int index = 0;
		for (int i = 0; i < fieldList.size(); i++) {
			ObjectNode fieldObjectNode =(ObjectNode)fieldList.get(i);
			String name =fieldObjectNode.get("name").asText();
			String columnName =fieldObjectNode.get("columnName").asText();
			boolean displayInForm =fieldObjectNode.get("displayInList").asBoolean();
			if (!displayInForm) {
				continue;
			}
			if (index % 2 == 0) {
				formRowTreeModel = new TreeModel();
				formRowTreeModel.setId("component" + id);
				formRowTreeModel.setName("row");
				root.addChild(formRowTreeModel);

				formRow = new Row();
				formRow.setId("component" + id);
				id++;
				formPage.addComponent(formRow);
			}

			TreeModel fieldTreeModel = new TreeModel();
			fieldTreeModel.setId("component" + id);
			fieldTreeModel.setName(name);
			formRowTreeModel.addChild(fieldTreeModel);

			String viewType =fieldObjectNode.get("viewType").asText();
			Field field = new Field();
			formRow.addComponent(field);
			field.setType(viewType);
			field.setId("component" + id);
			id++;
			field.setCol(2);
			field.setFieldcol(16);
			field.setLabelExpression(name);
			field.addProperty("dataSource", tableName);
			field.addProperty("dataField", columnName);

			index++;
		}

		if(!StringUtils.isEmpty(subTableName)) {
			DataSourceConfig subDataSourceConfig = new DataSourceConfig();
			dataSourceConfigList.add(subDataSourceConfig);
			Table subTable=tableStore.get(subTableName);
			subDataSourceConfig.setId(subTableName);
			subDataSourceConfig.setName(subTable.getName());
			subDataSourceConfig.setTableName(subTableName);

			
			ArrayNode subFieldList=(ArrayNode)objectNode.get("tableFieldSelectPage").get("subFieldList");
			
			TreeModel row2TreeModel = new TreeModel();
			row2TreeModel.setId("component" + id);
			row2TreeModel.setName("row");
			root.addChild(row2TreeModel);

			Row row2 = new Row();
			row2.setId("component" + id);
			id++;
			formPage.addComponent(row2);

			TreeModel tableTreeModel = new TreeModel();
			tableTreeModel.setId("component" + id);
			tableTreeModel.setName("table");
			row2TreeModel.addChild(tableTreeModel);

			com.codeoss.framework.view.json.Table tableJson = new com.codeoss.framework.view.json.Table();
			tableJson.setId("component" + id);
			tableJson.addProperty("dataSource", subTableName);
			tableJson.addProperty("editable",true);
			id++;
			row2.addComponent(tableJson);

			for (int i = 0; i < subFieldList.size(); i++) {
				ObjectNode fieldObjectNode =(ObjectNode)subFieldList.get(i);
				String name =fieldObjectNode.get("name").asText();
				String columnName =fieldObjectNode.get("columnName").asText();
				boolean displayInList =fieldObjectNode.get("displayInList").asBoolean();
				if (!displayInList) {
					continue;
				}

				TreeModel tableColumnTreeModel = new TreeModel();
				tableColumnTreeModel.setId("component" + id);
				tableColumnTreeModel.setName(name);
				tableTreeModel.addChild(tableColumnTreeModel);

				TableColumn tableColumn = new TableColumn();
				tableColumn.setTitle(name);
				tableColumn.setId("component" + id);
				tableJson.addComponent(tableColumn);
				id++;

				TreeModel labelTreeModel = new TreeModel();
				labelTreeModel.setId("component" + id);
				labelTreeModel.setName(name);
				tableColumnTreeModel.addChild(labelTreeModel);

				String viewType=fieldObjectNode.get("viewType").asText();
				Field field = new Field();
				field.setType(viewType);
				field.setId("component" + id);
				id++;
				field.setLabelExpression(name);
				field.addProperty("dataSource", subTableName);
				field.addProperty("dataField", columnName);
				field.setCol(4);
				field.setNoLabel(true);
				tableColumn.addComponent(field);
			}
		}
		ObjectMapper objectMapper = new ObjectMapper();
		try {
			String componentJson = objectMapper.writeValueAsString(formPage);
			List<TreeModel> rootList = new ArrayList<TreeModel>();
			rootList.add(root);
			String treeJson = objectMapper.writeValueAsString(rootList);
			IrPage irPage = new IrPage();
			irPage.setComponentModelJson(componentJson);
			irPage.setComponentTreeModelJson(treeJson);
			irPage.setCurrentComponentId(Long.parseLong(id + ""));
			irPage.setPageCode(pageCode);
			irPage.setName(pageName);
			irPage.setDevice("pc");
			irPage.setPageType("formview");
			irPage.setDescription(pageDescription);
			irPage.setModuleType(moduleType);
			
			irPageService.insert(irPage);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			throw new RuntimeException(e);
		}
	}
	
	private void createListView(PageWizardDialogRequest pageWizardDialogRequest,ObjectNode objectNode) {
		String moduleType=objectNode.get("moduleTypeSelectPage").get("moduleType").asText();
		String tableName=objectNode.get("dataSourceSelectPage").get("tableName").asText();
		String pageCode=objectNode.get("pageBaseInfoPage").get("pageCode").asText();
		String pageName=objectNode.get("pageBaseInfoPage").get("name").asText();
		String pageDescription=objectNode.get("pageBaseInfoPage").get("description").asText();
		ArrayNode fieldList=(ArrayNode)objectNode.get("tableFieldSelectPage").get("fieldList");
		
		Table table = tableStore.get(tableName);

		int id = 1;

		TreeModel root = new TreeModel();
		root.setId("component" + id);
		root.setName(table.getName() + "列表视图");

		Page listPage = new Page();
		listPage.setId("component" + id);
		id++;

		listPage.addProperty("pageCode", pageCode);
		listPage.addProperty("title", pageName);
		listPage.addProperty("pageBean", "listViewPageBean");

		List<DataSourceConfig> dataSourceConfigList = new ArrayList<DataSourceConfig>();
		listPage.setDataSourceList(dataSourceConfigList);

		DataSourceConfig dataSourceConfig = new DataSourceConfig();
		dataSourceConfigList.add(dataSourceConfig);
		dataSourceConfig.setId(tableName);
		dataSourceConfig.setName(table.getName());
		dataSourceConfig.setTableName(tableName);

		TreeModel searchRowTreeModel = null;
		Row searchRow = null;
		int index = 0;
		for (int i = 0; i < fieldList.size(); i++) {
			ObjectNode fieldObjectNode =(ObjectNode)fieldList.get(i);
			String name =fieldObjectNode.get("name").asText();
			String columnName =fieldObjectNode.get("columnName").asText();
			boolean displayInSearch =fieldObjectNode.get("displayInSearch").asBoolean();
			if (!displayInSearch) {
				continue;
			}
			if (index % 2 == 0) {
				searchRowTreeModel = new TreeModel();
				searchRowTreeModel.setId("component" + id);
				searchRowTreeModel.setName("row");
				root.addChild(searchRowTreeModel);

				searchRow = new Row();
				searchRow.setId("component" + id);
				id++;
				listPage.addComponent(searchRow);
			}

			TreeModel fieldTreeModel = new TreeModel();
			fieldTreeModel.setId("component" + id);
			fieldTreeModel.setName(name);
			searchRowTreeModel.addChild(fieldTreeModel);

			String viewType =fieldObjectNode.get("viewType").asText();
			Field field = new Field();
			searchRow.addComponent(field);
			field.setType(viewType);
			field.setId("component" + id);
			id++;
			field.setCol(2);
			field.setFieldcol(16);
			field.setLabelExpression(name);
			field.addProperty("dataSource", tableName);
			field.addProperty("dataField", columnName);

			index++;
		}
		TreeModel rowTreeModel = new TreeModel();
		rowTreeModel.setId("component" + id);
		rowTreeModel.setName("row");
		root.addChild(rowTreeModel);

		Row row = new Row();
		row.setId("component" + id);
		id++;
		listPage.addComponent(row);

		TreeModel searchButtonTreeModel = new TreeModel();
		searchButtonTreeModel.setId("component" + id);
		searchButtonTreeModel.setName("查询");
		rowTreeModel.addChild(searchButtonTreeModel);

		Button searchButton = new Button();
		row.addComponent(searchButton);
		searchButton.setId("component" + id);
		id++;
		searchButton.setLabelExpression("查询");
		searchButton.addProperty("onClickExpression", "@listViewPageBean.dataSearch()");

		TreeModel newButtonTreeModel = new TreeModel();
		newButtonTreeModel.setId("component" + id);
		newButtonTreeModel.setName("新建");
		rowTreeModel.addChild(newButtonTreeModel);

		Button newButton = new Button();
		row.addComponent(newButton);
		newButton.setId("component" + id);
		id++;
		newButton.setLabelExpression("新建");
		newButton.addProperty("onClickExpression",
				"@listViewPageBean.dataNew('" + tableName + "_formview')");

		TreeModel row2TreeModel = new TreeModel();
		row2TreeModel.setId("component" + id);
		row2TreeModel.setName("row");
		root.addChild(row2TreeModel);

		Row row2 = new Row();
		row2.setId("component" + id);
		id++;
		listPage.addComponent(row2);

		TreeModel tableTreeModel = new TreeModel();
		tableTreeModel.setId("component" + id);
		tableTreeModel.setName("table");
		row2TreeModel.addChild(tableTreeModel);

		com.codeoss.framework.view.json.Table tableJson = new com.codeoss.framework.view.json.Table();
		tableJson.setId("component" + id);
		tableJson.addProperty("dataSource", table.getTableName());
		tableJson.addProperty("editable",false);
		tableJson.addProperty("pageable", true);
		tableJson.addProperty("onPagination", "@listViewPageBean.dataPage()");
		tableJson.addProperty("onSort", "@listViewPageBean.dataSort()");
		tableJson.addProperty("multiSelect", true);
		id++;
		row2.addComponent(tableJson);

		for (int i = 0; i < fieldList.size(); i++) {
			ObjectNode fieldObjectNode =(ObjectNode)fieldList.get(i);
			String name =fieldObjectNode.get("name").asText();
			String columnName =fieldObjectNode.get("columnName").asText();
			boolean displayInList =fieldObjectNode.get("displayInList").asBoolean();
			if (!displayInList) {
				continue;
			}

			TreeModel tableColumnTreeModel = new TreeModel();
			tableColumnTreeModel.setId("component" + id);
			tableColumnTreeModel.setName(name);
			tableTreeModel.addChild(tableColumnTreeModel);

			TableColumn tableColumn = new TableColumn();
			tableColumn.setTitle(name);
			tableColumn.setId("component" + id);
			tableJson.addComponent(tableColumn);
			id++;

			TreeModel labelTreeModel = new TreeModel();
			labelTreeModel.setId("component" + id);
			labelTreeModel.setName(name);
			tableColumnTreeModel.addChild(labelTreeModel);

			
			Column column=table.getColumnByColumnName(columnName);
			if(column.getDataType().equals("boolean")) {
				Field field = new Field();
				field.setType("switch");
				field.setId("component" + id);
				id++;
				field.setLabelExpression(name);
				field.addProperty("dataSource", tableName);
				field.addProperty("dataField", columnName);
				field.setCol(4);
				field.setNoLabel(true);
				tableColumn.addComponent(field);
			}else if(column.getLookupInfo()!=null && column.getLookupInfo().getDictDef()!=null) {
				Field field = new Field();
				field.setType("tag");
				field.setId("component" + id);
				id++;
				field.setLabelExpression(name);
				field.addProperty("dataSource", tableName);
				field.addProperty("dataField", columnName);
				field.setCol(4);
				field.setNoLabel(true);
				tableColumn.addComponent(field);
			}else {
				Label label = new Label();
				label.setId("component" + id);
				id++;
				label.setLabelExpression(name);
				label.addProperty("dataSource", tableName);
				label.addProperty("dataField", columnName);
				tableColumn.addComponent(label);
			}
		}

		TreeModel actionColumnTreeModel = new TreeModel();
		actionColumnTreeModel.setId("component" + id);
		actionColumnTreeModel.setName("操作");
		tableTreeModel.addChild(actionColumnTreeModel);

		TableColumn actionTableColumn = new TableColumn();
		actionTableColumn.setTitle("操作");
		actionTableColumn.setId("component" + id);
		tableJson.addComponent(actionTableColumn);
		id++;

		TreeModel actionRowTreeModel = new TreeModel();
		actionRowTreeModel.setId("component" + id);
		actionRowTreeModel.setName("row");
		actionColumnTreeModel.addChild(actionRowTreeModel);

		Row actionRow = new Row();
		actionRow.setId("component" + id);
		id++;
		actionTableColumn.addComponent(actionRow);

		TreeModel editTreeModel = new TreeModel();
		editTreeModel.setId("component" + id);
		editTreeModel.setName("icon");
		actionRowTreeModel.addChild(editTreeModel);

		Icon editIcon = new Icon();
		editIcon.setId("component" + id);
		editIcon.setIconClass("el-icon-edit");
		editIcon.addProperty("onClickExpression", "@listViewPageBean.dataEdit('"+tableName + "_formview"+"')");
		editIcon.addProperty("cssStyleExpression", "color:green;");
		id++;
		actionRow.addComponent(editIcon);

		TreeModel deleteTreeModel = new TreeModel();
		deleteTreeModel.setId("component" + id);
		deleteTreeModel.setName("icon");
		actionRowTreeModel.addChild(deleteTreeModel);

		Icon deleteIcon = new Icon();
		deleteIcon.setId("component" + id);
		deleteIcon.setIconClass("el-icon-delete");
		deleteIcon.addProperty("confirmMessage","确认要删除吗?");
		deleteIcon.addProperty("onClickExpression", "@listViewPageBean.dataDelete()");
		id++;
		actionRow.addComponent(deleteIcon);

		ObjectMapper objectMapper = new ObjectMapper();
		try {
			String componentJson = objectMapper.writeValueAsString(listPage);
			List<TreeModel> rootList = new ArrayList<TreeModel>();
			rootList.add(root);
			String treeJson = objectMapper.writeValueAsString(rootList);
			IrPage irPage = new IrPage();
			irPage.setComponentModelJson(componentJson);
			irPage.setComponentTreeModelJson(treeJson);
			irPage.setCurrentComponentId(Long.parseLong(id + ""));
			irPage.setPageCode(pageCode);
			irPage.setName(pageName);
			irPage.setDevice("pc");
			irPage.setPageType("listview");
			irPage.setDescription(pageDescription);
			irPage.setModuleType(moduleType);
			
			irPageService.insert(irPage);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			throw new RuntimeException(e);
		}
	}

	@Override
	public PageWizardDialogResponse initDataSourceSelectPage() {
		// TODO Auto-generated method stub
		PageWizardDialogResponse pageWizardDialogResponse=new PageWizardDialogResponse();
		List<TableInfoDto> tableInfoList=new ArrayList<TableInfoDto>();
		pageWizardDialogResponse.setTableInfoList(tableInfoList);
		List<IrModel> irModelList=irModelService.list();
		for(int i=0;i<irModelList.size();i++) {
			IrModel irModel=irModelList.get(i);
			TableInfoDto tableInfoDto=new TableInfoDto();
			tableInfoList.add(tableInfoDto);
			tableInfoDto.setTableName(irModel.getTableName());
			tableInfoDto.setName(irModel.getName()+"("+irModel.getTableName()+")");
			Table table=tableStore.get(irModel.getTableName());
			tableInfoDto.setTreeTable(table.isTreeTable());
		}
		return pageWizardDialogResponse;
	}

	@Override
	public PageWizardDialogResponse initTableFieldSelectPage(String tableName) {
		// TODO Auto-generated method stub
		PageWizardDialogResponse pageWizardDialogResponse=new PageWizardDialogResponse();
		Table table=tableStore.get(tableName);
		List<Column> columnList=table.getAllColumnList();
		List<TableFieldDto> tableFieldList=new ArrayList<TableFieldDto>();
		pageWizardDialogResponse.setTableFieldList(tableFieldList);
		for(int i=0;i<columnList.size();i++) {
			Column column=columnList.get(i);
			TableFieldDto tableFieldDto=new TableFieldDto();
			tableFieldList.add(tableFieldDto);
			tableFieldDto.setColumnName(column.getColumnName());
			tableFieldDto.setName(column.getName());
			String viewType=viewUtil.getViewType(table, column);
			tableFieldDto.setViewType(viewType);
			if(column.isCodeColumn() ||column.isNameColumn()) {
				tableFieldDto.setDisplayInSearch(true);
			}
		}
		return pageWizardDialogResponse;
	}

	@Override
	public PageWizardDialogResponse initUReportSelectPage() {
		// TODO Auto-generated method stub
		PageWizardDialogResponse pageWizardDialogResponse=new PageWizardDialogResponse();
		YunContext yunContext=YunContext.getCurrentContext();
		Table modelTable=tableStore.get("ir_report");
		List<ValueNamePair> reportList = valueNamePairUtil.getValueNamePairList(yunContext, modelTable, null, false, false);
		pageWizardDialogResponse.setReportList(reportList);
		return pageWizardDialogResponse;
	}

	@Override
	public PageWizardDialogResponse initModuleTypeSelectPage() {
		// TODO Auto-generated method stub
		PageWizardDialogResponse pageWizardDialogResponse=new PageWizardDialogResponse();
		List<ValueNamePair> moduleTypeList=irDictService.getPairListByCode("moduleType");
		pageWizardDialogResponse.setModuleTypeList(moduleTypeList);
		return pageWizardDialogResponse;
	}
}
